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)
44.1 What do you ask first?
3 min read+10 XP
Step 1: Requirements (5 minutes)
| Letter | Candidate asks | Interviewer answers |
|---|---|---|
| Scope | "Cars, bikes, autos? Shared rides? Scheduled rides? Payments in scope? Driver earnings?" | "Cars and bikes, single rider. On-demand only. Payment at the end (cash or digital). Skip earnings." |
| Count | "How many drivers and rides?" | "Up to a million drivers online at peak; about 20 million rides a day across cities." |
| Access pattern | "How often do drivers send location?" | "Every 4 seconds while online." |
| Latency | "How fast must a match happen?" | "A driver should be assigned within seconds; the rider sees the car move live." |
| Exactness | "Can a driver get two riders? Can the price change after booking?" | "Neither. The quoted price is what the rider agrees to." |
Agreed requirements:
- Functional (verbs): drivers go online and stream their location; riders request a ride and see a price quote (with surge); the system matches a nearby driver, tracks the trip live, and completes it with a fare.
- Non-functional (adjectives): fast matching (seconds), live tracking, never double-assign a driver, consistent trip state despite flaky phones, scalable location ingestion, fair and stable prices, available per city.
Interviewer pushback:
- "Is 'nearest driver' the right goal?" → Nearest by arrival time, not straight-line distance. A driver across a river can be closest on the map and slowest to arrive (44.7).
Memory code: "Ask how many move, how often they report, and what can never happen twice."