Skip to content
SD-27 · Back to the write-up

Design a ETA and Location Sharing

Every ping updates the driver’s latest position and, during a trip, is pushed to the trip’s watchers through its channel; ETAs come from a precomputed road graph fed by live speeds.

Follow a request

Apps
Edge
Services and data
Pipelines and callers
Driver appPings every 4 s
Rider appLive map
Location ingestChecks every ping
Connection serversWebSockets
Location storeLatest per driver
Trip channelsOne per trip
Trip serviceTrips and shares
Location logEvery ping
ETA servicePrecomputed routes
Traffic processorSpeeds per road
DispatchPicks a driver
1driver → ingest · seq 8812The driver’s phone sends its position, heading and speed, numbered 8812.1 / 6

The numbers, at a glance

Of every 10 pings……5 come from drivers on a trip, and are pushed to watchers
on a trip ≈ 200,000/sfree ≈ 200,000/s
Requests a second at peakPolling vs. push for the same maps
ETA work after batchingOf 160,000 questions a second
Dispatch matrix calls and re-timed routes do the rest for free.

A ping, in order

The write to the store and the publish happen together; the log is off the live path.

Driver app
Location ingest
Location store
Trip channel
Connection server
Rider app
1 position, seq 8812
2 SET if newer
3 ok, on trip a91
4 PUBLISH trip:a91
5 point 8812
6 push over socket
7 ack
RequestResponseAsync, does not block

Getting the car onto the map

The first of the two decisions this question is about; the other is precomputed routing.

Poll every 2 s
Wasteful
GET location
mostly unchanged
car 3 s behind
+ Plain HTTP.− 480,000 req/s; 3 s late.
Push to every server
Does not scale
on-trip point
all servers
filter, mostly discard
+ No routing.− Each server reads every point.
Channel per trip
Our pick
PUBLISH trip:a91
subscribed servers
push to rider
+ 1 s; only needed servers.− Long-lived sockets to run.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 5,000 updates/sMake it work
Apps
App server
SQL databaseETA search
One server, a row per driver, polling, a graph search per ETA.
Stage 2 · ≈ 25,000 updates/sMemory and routes
Apps
Ingest × N
Location storeETA, precomputed
Latest positions in memory; precomputed routing.
Stage 3 · ≈ 100,000 updates/sPush and traffic
Apps
Ingest × NConnection servers
Location storeTrip channelsTrip service
Log + trafficETA
WebSockets, a channel per trip, road speeds from pings.
Stage 4 · ≈ 400,000 updates/sPeak scale
Apps
Ingest × NConnection servers
Location storeTrip channelsTrip service
Log + trafficETADispatch matrix
Matrix ETAs for dispatch and re-timed routes.
Was this walkthrough useful?Your vote tells us what to improve next.