SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 25
Design surge pricing for a ride-hailing app
When many riders open the app in an area with few free drivers, the fare goes up to draw drivers in and ration rides. A rider sees the multiplier in a quote before requesting and expects to pay what they were shown.
Requirements
- Every 30 seconds, compute a price multiplier for each area from recent demand (riders asking for quotes) and supply (available drivers).
- Return a quote with the multiplier for the rider's pickup point.
- Honour a quote for its validity window even if the area's multiplier changes in the meantime.
- Let operations cap or freeze multipliers for a city or area, effective within one minute.
Constraints and assumptions
- 300 cities divided into hexagonal cells of about 1 km²; up to 500,000 cells have activity at peak.
- 1.5 million online drivers send a location every 4 seconds (about 375,000 events per second).
- Up to 100,000 quote requests per second at peak; quote API p99 under 150 ms.
- Multipliers range from 1.0 to 5.0 in steps of 0.1; a quote is valid for 5 minutes.
Out of scope for the first sketch
Choosing the pricing curve itself (assume a function from supply and demand to a target multiplier) · Driver incentives and payouts · Matching drivers to riders · Payments
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design surge pricing for a ride-hailing app
Finish your first sketch before answering these. Cross out freely.
- A cell's multiplier jumps from 1.0 to 2.8 and back within two minutes. How do you stop prices from flickering?
- A rider was quoted 1.8× and requests the ride after the cell has moved to 1.2× (or to 2.5×). What do they pay, and how do you verify the quote?
- The stream processor falls three minutes behind. What multiplier do quotes use, and how do you notice?
- A quiet cell has 2 drivers and 1 rider. Why is its multiplier noisy, and how do you make it trustworthy?
- Operations must cap every multiplier in one city at 1.5× within a minute during an emergency. Where does that control live, and how does it reach quotes?
Compare afterwards: worked approaches and reading at sketchbook /questions/surge-pricing/review