Design a Surge Pricing
Design the surge pricing system of a ride-hailing app. The city is split into small hexagonal cells. For every cell, the system keeps comparing how many riders want a car with how many free drivers are nearby, and sets a price multiplier, such as 1.4×, that applies to rides starting there. Riders see the multiplier in their price quote; drivers see a heat map of busy areas so they can move towards demand.
At the global peak there are about 1.44 million drivers online, each sending a location ping every 4 seconds, and about 40,000 price quotes a second: some 400,000 events a second in all. Demand can jump in two minutes when a concert ends, so a multiplier must be at most 60 seconds old. It must also be stable and fair: it should not flicker between 1.0× and 2.5× from one refresh to the next, a rider must pay the price they were quoted, and every multiplier ever shown must be explainable later to a regulator.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1How fresh must a multiplier be?
- 2How big is a cell?
- 3What counts as demand?
- 4What counts as supply?
- 5Is the quoted price binding?
- 6Are there limits on the multiplier?
- 7Is it one global system?
- 8Do we need to explain past prices?
How to spend the 45 minutes
- 5minPart 1: Requirements and scope
- 5minPart 2: Estimates
- 5minPart 3: API
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Deep dives and trade-offs