SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 40
Design driver dispatch for ride requests
A rider taps Request and expects a driver to accept within seconds. The system has to choose among nearby available drivers, send one an offer, and move on quickly if that driver declines or ignores it, while thousands of other requests in the same city compete for the same drivers.
Requirements
- For each ride request, find available drivers near the pickup and choose one by estimated time to pickup, not straight-line distance.
- Send the chosen driver an offer they can accept or decline within 15 seconds; on decline or timeout, offer the ride to the next candidate.
- A driver is never assigned to two active rides, and a ride is never assigned to two drivers.
- The rider can cancel at any time; after 2 minutes without an acceptance, tell the rider no driver was found.
Constraints and assumptions
- 1.5 million online drivers send a location every 4 seconds; positions can be up to 8 seconds stale.
- Peak load is 2,000 ride requests per second worldwide, with the busiest city at 300 per second.
- The first offer should go out within 1 second of the request; candidate search must take under 100 ms.
- About 70% of first offers are accepted.
Out of scope for the first sketch
Pricing and surge · Live tracking after acceptance · Shared or pooled rides · Driver payouts and ratings
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design driver dispatch for ride requests
Finish your first sketch before answering these. Cross out freely.
- Two requests arrive at the same moment and both pick the same best driver. What prevents a double assignment?
- The driver taps Accept just as the 15-second offer expires, and the system has already started offering the ride to someone else. Who gets it?
- Choosing the best driver for each request one at a time is greedy. When would you match requests in batches instead, and what does it cost?
- The dispatch server for a city crashes with offers in flight. What state is lost, and how do rides and drivers recover?
Compare afterwards: worked approaches and reading at sketchbook /questions/dispatch-matching/review