44. Design Ride-Hailing with Surge Pricing (Uber / Rapido)
1
The interview prompt2
44.1 What do you ask first?3
44.2 How big is this, really?4
44.3 What are the doors?5
44.4 What do we store?6
44.5 What does the whole system look like?7
44.6 How are location updates handled?8
44.7 How does matching work?9
44.8 How does surge pricing work?10
44.9 How does the trip state machine work?11
44.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab44. Design Ride-Hailing with Surge Pricing (Uber / Rapido)
Score yourself
3 min read+10 XP
Score yourself
Give yourself 0, 1 or 2 points per row.
| Area | 0 points | 1 point | 2 points |
|---|---|---|---|
| Requirements | Started drawing | Request and match | Location rate, double assignment, price locking and live tracking agreed |
| Estimates | None | Numbers, not used later | Location writes vs ride volume drove in-memory index and city sharding |
| API and data | Skipped | Request endpoint only | Driver socket, quote with lock, idempotent trip events, index vs log vs trips |
| High-level design | DB query for nearest | Index, no matching flow | Quote, match by ETA, offer, atomic assign and trip states walked |
| Deep dive | Hand-waved | One topic | Index, ETA matching with atomic assignment, smoothed capped surge or state machine done properly |
| Trade-offs | None named | Named when asked | Raised unprompted (update rate vs battery, greedy vs batch matching, surge smoothing) |
| Communication | Long silences | Mostly clear | Thought out loud, checked in, managed time |
12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.
The bar: fresher vs SDE-2
| Fresher | SDE-2 | |
|---|---|---|
| Locations | Store in a table | In-memory cell index per city, stale expiry, history to a stream |
| Matching | Nearest by distance | ETA ranking, sequential offers with timeouts, atomic assignment, batch matching |
| Surge | Price × demand | Per-cell ratio, smoothing, caps, locked into quotes |
| Trips | Status column | State machine with idempotent events and timeouts |
| Scale | One cluster | Sharded by city, stateless matchers, cached ETAs |
Common mistakes
- Writing every location update to the main database.
- Matching by straight-line distance only.
- Offering one trip to many drivers at once without atomic assignment, so two accept the same rider, or one driver gets two.
- Recalculating price during the trip instead of locking the quote.
- Trusting the phone's view of trip state without idempotent events.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz