A food delivery app wants customers to watch their courier approach on a live map. At the dinner peak 120,000 couriers are on shift, and each courier's phone sends a GPS position every 4 seconds over a flaky mobile connection. About 400,000 customers have an order in progress and keep the tracking screen open. Positions should reach the customer within 2 seconds, and the app should also show an updated arrival estimate.
Functional requirements
Couriers' phones send their position every 4 seconds while on a delivery
Customers see their own courier's live position and route on a map
Show an estimated arrival time that updates as the courier moves
Operations staff can see all couriers in a city
Non-functional requirements
A new position reaches the customer within 2 seconds at p95
Customers can only see the courier for their own active order
Losing an occasional position update is acceptable; showing a stale courier for minutes is not
Courier location history is kept for 30 days for disputes
Constraints and scale
120,000 active couriers at peak, 30,000 location updates per second
400,000 customers watching a live map at once
Each update is about 200 bytes: courier ID, order ID, coordinates, heading, timestamp
You will practise
Push updates to clients over persistent connections instead of polling
Keep only the latest position in memory and stream the history elsewhere
Route each update to exactly the viewers who care about it
Show 2 hints
400,000 customers polling every 2 seconds is 200,000 requests per second of mostly 'nothing changed'. What is the alternative?
A customer's connection and the courier's updates probably land on different servers. How do they meet?