MSD-101 · Deep dives: hard problems, solved
Live driver location at scale
⏱ 14 min 🎮 Hands-on ☁ Azure ✓ Completed
⚡ The 30-second answer
Live location is a stream, not an API: phones send small GPS points over one WebSocket, a stream (Event Hubs) absorbs the peak, readers keep only the latest point per driver in an in-memory geo index with an expiry, and every raw point is archived for fares. The phone decides the cost: the GPS interval sets traffic and battery, and an offline buffer keeps tunnels from leaving gaps.
- Size a GPS stream
- Latest point vs full history
- Scale readers on lag
- Battery-aware intervals
Try it
Play with the design before you read about it. Everything runs on this page.
No Azure subscription needed. Read the requirement, see the architecture, build it in a mock portal, send a booking through it, then break it.
☁ Simulate on Azure: Live driver location at scale
At 6 pm, 1 million drivers are online. Each phone sends its position every few seconds. Riders want the car to move smoothly, drivers want their battery to last a 10-hour shift, and nothing may be lost in a tunnel.
It must
- Driver phones stream GPS while online
- The latest position of every driver is searchable in milliseconds
- Riders on a trip see their car move live
- Raw points are kept for fares, disputes and analytics
With these numbers
- Ingest
- 250k events/s
- Car on map
- ≤ 5 s old
- Battery
- < 10% per hour
- Data loss
- 0 points on a trip
Each box is one Azure service. Tap a box (or Tab to it) to see its job and why it is there.
Create each resource. The defaults are a good design; change a setting and read why it matters. Some choices decide what breaks later.
Home › Create a resource › iOS / Android
Remote config: driver app location settings
ⓘ 1 s quadruples traffic and battery use; 15 s makes the car jump.
ⓘ Waiting drivers do not need high accuracy; save the battery.
ⓘ Tunnels and car parks must not leave gaps in the route.
Deployment in progress…
Microsoft.iOS/Android · resource group rg-live-location
Home › Create a resource › Azure Web PubSub
Create Web PubSub service
ⓘ One unit holds 1,000 concurrent connections; 1M drivers need many units (or several resources).
ⓘ Sends client events straight into Event Hubs, with no web tier in the middle.
Deployment in progress…
Microsoft.WebPubSub · resource group rg-live-location
Home › Create a resource › Azure Event Hubs
Create Event Hubs namespace
ⓘ Standard tops out at 40 throughput units (about 40k events/s). 250k events/s needs Premium or Dedicated.
ⓘ Partition by city so readers can work in parallel.
ⓘ Keeps every raw point for fares and disputes, with no extra code.
Deployment in progress…
Microsoft.EventHubs · resource group rg-live-location
Home › Create a resource › Azure Container Apps
Create Container App: location-service
ⓘ Adds replicas when unread events pile up.
ⓘ No more than one reader per partition is useful.
Deployment in progress…
Microsoft.ContainerApps · resource group rg-live-location
Home › Create a resource › Azure Managed Redis
Create Azure Managed Redis
ⓘ Drivers who go silent disappear on their own.
Deployment in progress…
Microsoft.ManagedRedis · resource group rg-live-location
Everything is deployed. Your architecture is lit up below. Go to Run to send a request through it.
Request: One GPS point from a driver on a trip
⚠️ Event Hubs Premium and many Web PubSub units cost real money every hour. Test with Standard tiers and a few simulated drivers.
- Create Web PubSub (Standard, 1 unit) and Event Hubs (Standard) in a test resource group.
- Add a Web PubSub event listener that targets the event hub.
- Run a small script that sends GPS points from 100 fake drivers.
- Read them with a Container App and write the latest point to Redis with an expiry.
- Delete the resource group when done.
* Illustrative prices to compare designs, not a quote.
What breaks, and the fix
| Failure | User sees | Why | Fix |
|---|---|---|---|
| 🚇 Driver in a tunnel for 2 minutes | A straight line through the city and a wrong fare | Points sent while offline were thrown away | Buffer up to 5 minutes and send oldest first |
| 🌆 1M drivers online at 6 pm | Frozen cars at rush hour | The stream had a fixed, small capacity | Event Hubs Premium or Dedicated, partitioned by city |
| 🐢 Readers fall behind at rush hour | Cars jumping, matches to drivers who already left | Readers could not keep up | Scale readers on stream lag (KEDA) |
| 🔋 Drivers complain about battery | Drivers turn the app off | GPS every second | Interval by trip state; smooth animation on the rider phone |
🎓 Education-only simulation. Nothing is created in Azure and no subscription is needed.
Drag the sliders. One small number on the phone (the GPS interval) changes the whole backend.
Stream vs command
Live data can lose a point. Commands must happen exactly once. Give them different roads.
GPS points ride the WebSocket every 4 s. One lost? The next one replaces it.
Idempotency key
Send the same ID on every retry. The server returns the first result instead of doing it again.
Book with key k7. The trip is saved… but the reply is lost in the lift.
Outbox + backoff
Save the command on the phone first, then send it. Wait longer after every failure.
The tap is saved to the local outbox. Even if the app dies now, it is not lost.
Geo index + expiry
Keep only the latest position per driver in memory, and let it expire after 30 s.
Every ping overwrites the driver’s last position and resets a 30 s timer.
Pub/sub fan-out
Publish one event to a group. Everyone in the group gets it, however many they are.
The trip service publishes once: “car moved”.
Push to wake, then re-sync
A push only says “something changed”. The app then asks the server for the truth.
The app is in the background, so its socket is closed. The server sends a push.
- The problemAt 6 pm a city has 80,000 drivers online. The cars on the rider map start to freeze, matching sends drivers who left 10 seconds ago, and drivers say the app eats their battery by lunch.
- The design ideaHot index for now, cold archive for the record.
- In real lifeDelivery and ride apps across Southeast Asia run the same split: a hot index for matching and a cold archive for money and analytics. The archive is often what settles a fare dispute.
Start with a question
At 6 pm a city has 80,000 drivers online. The cars on the rider map start to freeze, matching sends drivers who left 10 seconds ago, and drivers say the app eats their battery by lunch.
All three problems come from one design: treating GPS like normal API calls.
Explain it like I'm 10
Imagine every taxi shouting “I am here” every 4 seconds. A smart helper writes down only the newest shout for each taxi on a whiteboard, and also drops every shout into a big box for later. The whiteboard is fast; the box is complete.
The technical explanation
Ingest. Each driver phone keeps one WebSocket to Azure Web PubSub and sends a ~120-byte point. A Web PubSub event listener forwards points into Azure Event Hubs, partitioned by city. At 1M drivers every 4 s that is ~250k events/s, beyond Event Hubs Standard (40 throughput units), so use Premium or Dedicated, or a namespace per region.
Two copies, two jobs. A location service on Azure Container Apps reads the stream and writes only the latest point per driver to an Azure Managed Redis geo index with a 30 s expiry. Event Hubs Capture writes every raw point to Data Lake Storage for fares, disputes and analytics.
Keep up. Scale readers on stream lag with a KEDA Event Hubs rule, up to one reader per partition. Watch lag in Application Insights: it is the first sign the pipeline is too small.
The phone. GPS every 4 s on a trip, every 15–30 s while waiting, batched when the signal is weak, buffered for up to 5 minutes offline and sent oldest first. The rider app animates between points so 4 s looks live.
| Decision | Choice | Why |
|---|---|---|
| Transport | WebSocket (Web PubSub) | One connection, no request per point |
| Buffer | Event Hubs, partition by city | Absorbs peaks; parallel readers |
| Hot data | Redis geo index, 30 s expiry | Fast “near me”, silent drivers vanish |
| Cold data | Event Hubs Capture → Data Lake | Full routes for fares and disputes |
| Phone | 4 s on trip, 20 s idle, offline buffer | Battery and complete routes |
Real-world scenario
Delivery and ride apps across Southeast Asia run the same split: a hot index for matching and a cold archive for money and analytics. The archive is often what settles a fare dispute.
Test yourself
5 questions. Get 4 right and this lesson is marked complete.
Pass the quiz to complete this lesson.
Next: Payments without double charges →Questions people ask
How do apps like ride-hailing track drivers in real time?
Phones stream small GPS points over a WebSocket into a stream service; a reader keeps the latest point per driver in an in-memory geo index for matching, and the full stream is archived for fares and analytics.
Why not send driver GPS points to a REST API?
At 1M drivers every 4 s that is about 250,000 requests a second, so the API tier becomes huge and costly. One WebSocket per phone into a stream service handles the same load with far fewer servers.
Can I calculate fares from the live location index?
No. The live index keeps only the latest point per driver and drops it after 30 s. Fares come from the full route, which Event Hubs Capture archives in Data Lake Storage.
How often should a driver app send GPS?
About every 4 s on a trip or on the way to a pickup, every 15–30 s while waiting, and less when the battery is low. Smooth animation on the rider phone hides the gap.
Interview questions
How this topic comes up in system design interviews. Answer out loud first, then open the model answer.
intermediate Design the location pipeline for 1M drivers.
WebSocket ingest (Web PubSub) → Event Hubs partitioned by city (Premium) → readers on Container Apps scaled on lag → Redis geo index with expiry; Event Hubs Capture to Data Lake for history; monitor lag.
advanced How do you detect fake GPS?
Check speed and jumps between points, compare with cell or Wi-Fi hints where allowed, flag mock-location settings on Android, and review flagged drivers by stream analytics plus a human queue.
Quick revision
Remember
- Size a GPS stream
- Latest point vs full history
- Scale readers on lag
- Battery-aware intervals
- Never compute fares from the Redis index. It only keeps the latest point. Fares come from the full route in the archive.
One line to remember
“Hot index for now, cold archive for the record.”
Official documentation
- Web PubSub event listener (Microsoft Learn)
- Event Hubs Capture (Microsoft Learn)
- Scale Container Apps (Microsoft Learn)