failover
← All labs

Hard · 13 steps · ~85 min

Design a delivery dispatch system

Pick the right rider for every order, as riders and orders move.

Customers place orders, thousands of riders move around a city, and the system must pair each order with a good free rider within seconds, never give one order to two riders, and keep working at the dinner rush.

Same problem as SwiggyDoorDashUber Eats

How it works

What you'll build

  1. The API and the data behind it
  2. A system for 400 requests a second, then a cheap design for 5,000 location pings
  3. A durable queue and workers that absorb the dinner rush
  4. A realtime tier, replicas and a limiter for 40,000+
  5. A design that survives losing a gateway, a cold cache and the primary database
  6. The matching decisions: batching, atomic claims and geo-indexing

Steps

  1. 1Design the API
  2. 2Design the data model
  3. 3Handle 400 requests/sec
  4. 4Rider pings at 5,000 requests/sec for $800 a month
  5. 5Absorb the dinner rush: 12,000 requests/sec
  6. 6Handle 40,000 requests/sec
  7. 7Survive a retry storm on the same budget
  8. 8Lose a realtime gateway
  9. 9Survive a cold position cache
  10. 10Lose the primary database
  11. 11Match the nearest rider, or batch?
  12. 12Two riders got the same order
  13. 13Deep dive: finding riders near a point
Start the lab →