Step 1: Requirements and estimates
Functional requirements:
- Drivers go online, share their location every few seconds, receive ride offers, accept or decline them.
- Riders see nearby cars, request a ride, see the assigned driver approaching, and pay at the end.
- The system matches a request with a good nearby driver.
Non-functional requirements:
- Fast matching: a few seconds from request to assigned driver.
- Never double-book a driver.
- Fresh positions: cars on the map are at most a few seconds old.
- Battery and data friendly on phones.
An important observation: the system holds two very different kinds of data:
- Driver locations: enormous numbers of updates, but only the latest one matters. Losing one update is fine; the next arrives in seconds.
- Trips and payments: far fewer, but each one must be stored safely and never lost.
They need different storage.
Clarify scope: matching and location (the usual focus), versus pricing, surge, routing and payments (mention, don’t design). Key properties: location updates are high-frequency overwrites with short value (seconds), so they belong in memory with replication, not in a transactional database; trips are a durable state machine; matching is latency-sensitive and needs a consistency guarantee on driver assignment, not on positions. Traffic is geographically partitioned: a ride in Belgrade never needs drivers in Lisbon, so shard by city or region (and design for cross-boundary areas near borders). ETA comes from a routing service with live traffic; straight-line distance is only a pre-filter.
Active drivers (peak): 1 million worldwide, update every 4 s
Location writes: 1e6 / 4 s = 250,000 / s (mostly overwrites of the latest position)
Payload: ~100 B (driver id, lat, lng, heading, speed, timestamp) → 25 MB / s inbound
Ride requests: 20 million / day → ~230 / s average, ~2,000 / s peak (rain, events)
Nearby-driver queries: requests × a few lookups, plus riders' map views (cached, coarse)
Trip storage: 20e6 × ~2 KB ≈ 40 GB / day (durable, kept for years)
Location history for trips: sampled every few seconds during trips only, batched to cheap storage- 250,000 writes per second of positions would overwhelm a normal SQL database, and keeping every point forever is pointless. The latest position per driver is what matching needs.
- 2,000 ride requests per second at peak is modest; each one must be handled carefully, but the volume is easy.
- Positions during a trip are kept (for the receipt and disputes), but written in batches to cheap storage.
- Location: ~250k writes/s of overwrites, value lasts seconds → in-memory, replicated, sharded by region; not a transactional DB.
- Trips: low volume (~2k/s peak requests), durable state machine; payments handed off.
- Matching in seconds, ranked by ETA (routing service), with exactly-one assignment per driver.
- Partition by city/region; handle borders; trip location samples batched to cold storage.
Check this part
Why not write every driver location update to the main SQL database?
Which property needs strong consistency in ride matching?