Part 2 of 8 · 1 min read
Scope
Riders, drivers and a map.
Think of a dispatcher at a taxi office with a live map. A call comes in, the dispatcher finds the nearest free car, offers the job, and if the driver declines, tries the next one.
Questions and assumptions here (made up).
- Who uses it? Riders request trips, drivers go online and accept them.
- Scale? 20 million trips a day, 5 million drivers, 2 million online at the busiest hour.
- Core flow? Request a ride, see nearby drivers and a price estimate, get matched, track the driver, ride, pay.
- Matching time? A rider should be matched within a few seconds.
- Correctness? A driver must never get two trips at once, and a trip must not be charged twice.
Numbers (made up).
- Trips: 20,000,000 a day, about 230 a second on average. Peak 5 times: about 1,200 a second.
- Driver location updates: 2,000,000 drivers online, each sends a location every 4 seconds: 500,000 updates a second.
- Size: 100 bytes each, so 50 MB/s.
- Location data is useful only while fresh. Only the latest position per driver matters for matching, so 2,000,000 × 100 B = 200 MB in memory.
- Rider app polling or streaming for the driver's position: during a trip, an update every 2 to 4 seconds. If 1 million trips are active, that is about 250,000 to 500,000 pushes a second.
- Trip records: 20,000,000 × 2 KB = 40 GB a day.
Findings: the load is dominated by location writes, which are small and short-lived. Trips are few and need strong correctness. Two different kinds of storage follow.