Question breakdowns
Design a ride-hailing backend
Riders request, drivers move, and a match has to happen in seconds against a map that changes every few seconds. The interview is location indexing, matching without double-booking, and a trip state machine that survives flaky phones.
“Design Uber” is one of the most common senior system design questions because it has a bit of everything: a firehose of writes (driver locations), a geospatial query under a latency budget (nearby drivers), a concurrency problem with real consequences (one driver, two riders), and a long-running workflow on unreliable clients (the trip).
The trap is spending forty minutes on boxes and arrows. The interviewer is waiting for three deep dives, and this breakdown is organised around them.
Requirements
Pin these down in the first five minutes; they change the design.
Functional
- A rider sees nearby available drivers and an ETA, and requests a ride with pickup and drop-off.
- The system offers the request to a suitable driver, who accepts or declines within ~10 seconds.
- Both see each other’s live location during pickup and the trip.
- The trip moves through its states to completion; the fare is computed; payment is taken.
Non-functional
- Matching latency: a rider should get a driver within seconds; the matching query itself must be well under 100 ms.
- No double-booking: a driver is never assigned to two trips at once. This is a correctness requirement, not a preference.
- Availability over consistency for location display — a driver dot a few seconds stale is fine.
- Consistency over availability for trip state and payment.
- Scale: a large city at peak, and many cities.
Out of scope unless asked: surge pricing models, routing/ETA engine internals, driver onboarding, ratings. Name them, park them.
Say the split out loud: location is high-volume, ephemeral and can be stale; trips are low-volume, durable and must be correct. They want different storage, and saying so in minute five frames the whole design.
Back-of-the-envelope
- Drivers online at peak: say 1 million globally, 50,000 in the biggest city.
- Location updates: every 4 seconds per online driver → 1M / 4 = 250,000 writes/s globally, 12,500/s in the biggest city. Each update is ~100 bytes.
- Ride requests: say 20 million trips/day → ~230/s average, ~1,000/s at peak.
- Nearby-driver queries: riders browsing the app ask far more often than they book — say 10× → 10,000/s at peak.
Location writes dominate by two orders of magnitude, and nobody needs yesterday’s driver positions in the hot path. That rules out writing every ping to a relational database.
API
POST /v1/drivers/me/location {lat, lng, heading, ts} -- every ~4 s, from the driver app
GET /v1/drivers/nearby?lat=&lng= → [{driver_id, lat, lng, eta}] -- rider app, while browsing
POST /v1/trips {pickup, dropoff, product} → {trip_id, status: "matching"}
POST /v1/trips/{id}/accept (driver) → 200 or 409 if already taken
POST /v1/trips/{id}/events {type: "arrived" | "started" | "completed", ts}
GET /v1/trips/{id} → current state, both locations
Location updates go over a persistent connection (WebSocket or MQTT) rather than individual HTTP requests in practice — 250,000 TLS handshakes a second is avoidable cost — and the server pushes trip offers and live updates back over the same connection.
High-level design
Driver app ──ws──▶ Location service ──▶ Geo index (Redis, sharded by city/cell)
▲ │
│ └──▶ Kafka: location stream ──▶ trip tracking, analytics
│
Rider app ──▶ API gateway ──▶ Trip service ──▶ Postgres (trips, state machine)
│
└──▶ Matching service ──▶ Geo index (nearby query)
│
└──▶ offer to driver ──ws──▶ Driver app
- Location service: terminates driver connections, writes each driver’s latest position into a geo index, and publishes the stream to Kafka for consumers that need history.
- Geo index: in-memory, holds only the current position and status of online drivers.
- Trip service: owns trips and their state machine in Postgres.
- Matching service: for a new request, queries the geo index for candidates, ranks them, and offers the trip to drivers one at a time (or a few in parallel) until one accepts.
The members’ section takes the three deep dives — the geo index, matching without double-booking, and the trip state machine — and the failure modes.
The rest of this lesson is ₹1
Geospatial indexing with geohash and H3, matching without double-booking, the trip state machine and flaky phones, live tracking fan-out, multi-city partitioning, failure modes, and the follow-ups.
PhonePe, Google Pay, Paytm or any UPI app. Cards and net banking work too. One payment unlocks this lesson on this device.