Lesson 8 of 14
❮Prev Next❯

MSD-101 · Deep dives: hard problems, solved

Live driver location at scale

⏱ 14 min 🎮 Hands-on ☁ Azure

8of 14

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    ⚡ 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

    🎓 Education-only simulation. Nothing is created in Azure and no subscription is needed.

    1. 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.
    2. The design ideaHot index for now, cold archive for the record.
    3. 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.

    DecisionChoiceWhy
    TransportWebSocket (Web PubSub)One connection, no request per point
    BufferEvent Hubs, partition by cityAbsorbs peaks; parallel readers
    Hot dataRedis geo index, 30 s expiryFast “near me”, silent drivers vanish
    Cold dataEvent Hubs Capture → Data LakeFull routes for fares and disputes
    Phone4 s on trip, 20 s idle, offline bufferBattery and complete routes

    ☁ Simulate on Azure🎛 Size the load🧩 Patterns

    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.

    Ready for more?The full lesson adds the technical explanation, interview questions and quick revision.

    Test yourself

    5 questions. Get 4 right and this lesson is marked complete.

    1. 1. Why keep only the latest point per driver in Redis?
    2. 2. Event Hubs Standard tops out at 40 throughput units. What does 250k events/s need?
    3. 3. How should readers scale?
    4. 4. A driver goes through a tunnel for 2 minutes. What should the app do?
    5. 5. What keeps raw points without extra code?

    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