Design Live Order Tracking: Location Ingestion and Real-Time Push
How a delivery partner's GPS pings reach the customer's map within a second: write-heavy ingestion, latest location in memory, pub/sub per order and WebSocket push.
Live order tracking shows a customer where their delivery partner is on a map, moving in near real time, together with an estimated arrival time. Food delivery, e-commerce and ride apps all have this feature.
The system has two halves with very different characteristics. Ingestion receives a continuous stream of GPS updates from every active delivery partner. Distribution pushes each update to the one or two people who care about that particular order. These notes cover both.
1. Requirements
- Functional: the delivery partner's app reports its location every few seconds while an order is active.
- Functional: the customer sees the partner's position on a map with an ETA, updated live.
- Functional: status events such as 'picked up' and 'arriving' are shown and can trigger notifications.
- Non-functional: low latency. An update should reach the customer within one or two seconds.
- Non-functional: high availability; losing an occasional location point is acceptable because the next one replaces it.
- Workload: write-heavy on ingestion; many long-lived connections on the delivery side.
2. Scale estimation
Assume 500,000 delivery partners are active at peak and each sends a location every 5 seconds. That is 100,000 location writes per second. Assume 1 million orders are in progress and their customers have the tracking screen open: 1 million concurrent connections for pushing updates. Each update is small, about 100 bytes, so ingestion traffic is around 10 MB per second. Stored as history, 100,000 points per second is roughly 8.6 billion points per day, close to 1 TB per day, which calls for a write-optimised store and a retention policy.
3. Two kinds of location data
The same GPS ping serves two purposes with different storage needs, and separating them is the first design decision.
- Latest location: needed immediately, read frequently, overwritten every few seconds. It belongs in an in-memory store such as Redis, keyed by partner or order, with a TTL so that a silent device is noticed.
- Location history: needed later for route replay, distance-based payouts, disputes and analytics. It is append-only and large. It is written through a queue into a time-series or wide-column store, off the real-time path.
4. Ingestion path
The partner app sends pings to a location service. The service validates the ping, updates the latest location in Redis, and publishes the event to a stream such as Kafka, partitioned by order or partner ID so that the events of one order stay in sequence. It then returns immediately.
Consumers of the stream do the slower work independently: one writes history in batches, one recalculates ETA, one checks geofences for alerts. Because these are decoupled by the stream, a slow history database never delays the live update. The app can also reduce load at the source by batching a few points per request and by sending less often when the vehicle is stationary.
# Partner app -> Location service (HTTPS or a persistent connection)
POST /api/v1/locations
{ "orderId": "o_771", "partnerId": "d_42",
"points": [ { "lat": 12.9716, "lng": 77.5946, "speed": 7.2, "heading": 85, "ts": 1767225600 } ] }
# Customer app -> Tracking gateway
WebSocket wss://track.example.com/orders/o_771?token=<signed token>
# Tracking gateway -> Customer app (server push)
{ "type": "LOCATION", "lat": 12.9718, "lng": 77.5951, "heading": 85,
"etaSeconds": 420, "ts": 1767225605 }
{ "type": "STATUS", "value": "PICKED_UP" }5. Delivery path: push, not polling
The simple way for the customer app to get updates is to request the location every second. With a million customers tracking, that is a million requests per second, most of which return a position that has not changed since the previous request, because the partner only reports every five seconds.
Instead, the customer app opens one persistent connection to a tracking gateway and the server pushes an update only when there is one. A WebSocket is the usual choice. Since the data flows in one direction only, server to client, Server-Sent Events is a simpler alternative that works over plain HTTP. When the app is first opened or reconnects, it fetches the latest location from Redis so that the map is correct immediately, and then receives live updates.
6. Routing an update to the right customer
There are many gateway servers, and the customer tracking a given order is connected to just one of them. The location service does not know which. The link between the two halves is publish and subscribe, with one channel (topic) per order.
When a customer opens the tracking screen for order o_771, their gateway server subscribes to the channel for o_771. When a location update for that order arrives, it is published to that channel, and the pub/sub system delivers it only to the gateway servers that subscribed. The gateway then writes it to the customer's connection. When the order completes, the channel is closed and the subscription removed.
Partner app --GPS ping every ~5 s--> Location service
|
+--------------------+---------------------+
v v
Redis: latest location (TTL) Kafka: location events
loc:order:o_771 |
^ +---------------------+------------------+
| initial fetch v v v
| History writer ETA service Geofence / alerts
| (time-series DB) | ("arriving soon")
| v
| Pub/Sub channel per order: order:o_771
| |
Tracking gateway (WebSocket servers) <-----------+ (only subscribed gateways)
|
v
Customer app: map marker + ETA7. Making the map look right
Raw GPS readings are noisy. A phone in a street with tall buildings can report a position inside a building or on a parallel road, and updates arrive only every few seconds. Two techniques make the display smooth and believable.
Snap-to-road, or map matching, takes the raw points and aligns them to the most likely road segment on the map, removing jitter. Interpolation is done on the client: instead of jumping the marker from one reported position to the next, the app animates it along the road between the two points over the interval, so the vehicle appears to move continuously even though only one update arrives every five seconds.
8. ETA and geofence alerts
ETA is recalculated from the partner's current position, the remaining route and current traffic. It does not need to be recomputed on every ping; every 30 seconds or on a significant deviation from the route is sufficient, and the result is pushed over the same channel.
Alerts such as 'your order is arriving' use geofencing. A virtual boundary, for example 300 metres around the delivery address, is defined when the order is created. As pings arrive, a consumer checks whether the partner has entered the boundary. Comparing geohash cells makes this check cheap. When the boundary is crossed for the first time, a notification event is emitted once.
9. Failure handling
- Partner loses network: the app buffers points and sends them when the connection returns; the server uses timestamps to order them and ignores points older than the latest one for the live view.
- No pings for a while: the TTL on the latest location expires, and the customer app shows 'last updated a minute ago' instead of a misleading live marker.
- Customer connection drops: the app reconnects with backoff, fetches the latest location, and resubscribes. No replay is needed, since only the newest position matters.
- Gateway server fails: its connections are lost; clients reconnect through the load balancer to another gateway.
- Security: the tracking token is tied to the order and the customer, and expires when the order is completed.
Interview summary
- Requirements: updates within a second or two, write-heavy ingestion, many open connections.
- Latest location in Redis with a TTL; history through Kafka into a time-series store.
- Deliver by server push over WebSocket or SSE, not by polling.
- Route updates with a pub/sub channel per order to the subscribed gateway.
- Polish: snap-to-road, client-side interpolation, periodic ETA, geofence alerts.
Summary
Live tracking separates ingestion from distribution. GPS pings update an in-memory latest position and flow through a stream to history, ETA and alerting consumers. Customers hold a persistent connection and receive pushed updates routed through a per-order pub/sub channel. Map matching and interpolation turn sparse, noisy points into a smooth moving marker.
Puneet Tiwari
Full Stack Developer
