1 of 13

Software Crafters

Meet-up22

Architecture Kata

2 of 13

Let's Introduce ourselves

  • Name
  • Where you work/study

What would you do, if you bumped your car into someone’s else and there was nobody around?

3 of 13

Timeline

2.00 - 3.00: Kick-off & discussion

3.00 - 4.00: Architecture Kata in mobs

4.00 - 4.50: Groups present their solutions

4.50 - 5.00: Retrospective

4 of 13

Consider Ambulance as a Service

  1. Ambulance can be requested from a mobile device
  2. Ambulance’s location can be traced in real time.
  3. Ambulance can see areas most affected by Covid
  4. Ambulance where about for a day can be plotted on map

MySQL

Database

Ambulance Web Server

Customer

Mobile App

Ambulance

Mobile App

5 of 13

Problem?

If one ambulance sends location once in 3 seconds

Pings in minute = 20

If 1000 Ambulance sends location once in 3 seconds

Pings in minute = 20,000

Pings in second = 333.33

One Ambulance

1000 Ambulance

6 of 13

Message Queues

  1. A highly available service (messages are never lost)
  2. Producer can push messages
  3. Consumers poll message queue and process the messages
  4. Consumer consumes message at its own pace

Ambulance Web Server

7 of 13

Problem?

SELECT geo_hash(pickup_latitude, pickup_longitude), COUNT(1)

FROM ambulance_requests ar

JOIN patient p ON ar.patient_id = p.id

WHERE p.disease = 'Covid-19'

AND ar.date > date_sub(NOW(), INTERVAL 30 DAY)

GROUP BY 1;

10 Cases in a week vs 10 Cases in an hour

100 Rows vs 10000 Rows

8 of 13

Caches

  1. Calculate results once and store them for
    1. Faster retrieval
    2. Avoiding expensive operation running again and again
  2. Runs at O(1)
  3. Is basically a key/value pair

When to cache? (examples)

  1. Expensive database query
  2. Expensive computation
  3. Expensive http call
  4. The result is predetermined based on arguments

9 of 13

Problem?

ambulance_id

datetime

lat

lng

...

...

...

...

If 1000 Ambulance sends location once in 3 seconds

Pings in second = 333.33

Pings in minute = 20000

Pings in day = 28,800,000

Pings in month = 864,000,000

NoSQL pings

10 of 13

SQL

  • Good for running aggregations
  • Good for transactions
  • Only vertically scalable
  • Any column can be queried efficiently with help of index

NoSQL

  • Good for parent/child hierarchy
  • Horizontally scalable
  • Can only be queried with primary key

11 of 13

Let’s create something

12 of 13

Scalable Chat Application

  • Must
    • Should be able to handle 100k messages being sent per hour
    • Should receive message instantly
    • Should be able to retrieve a specific conversation within one second
    • Should be able to create groups and have group conversations
    • Should be able to delete recent messages from receiver’s end
  • Good to Have
    • Should be able to reply to a specific message
    • Should be able to have threads
    • Should be able to understand the demographics of users (active users in Karachi at 10pm)

13 of 13

BreakoutRooms

BreakoutRooms

BreakoutRooms

RETRO

Everyone discusses their solution

Discussion on what Kata is about

4.00 pm

3.00 pm