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
- Riders stream their location, the system keeps an index of where everyone is.
- A new order triggers matching: find nearby free riders, offer the order, and record whoever accepts.
What you'll build
- The API and the data behind it
- A system for 400 requests a second, then a cheap design for 5,000 location pings
- A durable queue and workers that absorb the dinner rush
- A realtime tier, replicas and a limiter for 40,000+
- A design that survives losing a gateway, a cold cache and the primary database
- The matching decisions: batching, atomic claims and geo-indexing
Steps
- 1Design the API
- 2Design the data model
- 3Handle 400 requests/sec
- 4Rider pings at 5,000 requests/sec for $800 a month
- 5Absorb the dinner rush: 12,000 requests/sec
- 6Handle 40,000 requests/sec
- 7Survive a retry storm on the same budget
- 8Lose a realtime gateway
- 9Survive a cold position cache
- 10Lose the primary database
- 11Match the nearest rider, or batch?
- 12Two riders got the same order
- 13Deep dive: finding riders near a point