Case studies
Driver location ingestion
How a stream of driver location updates, about 250,000 per second for a large region, reaches an in-memory geo index, and why the matchable set holds only available drivers.
Every online driver's app sends its position every few seconds. Those updates are the highest-volume traffic in a ride-sharing system. The ingestion path has to take them in, keep the newest position for each driver, and drop drivers who stop reporting. It does not need a history for matching. Only the latest position matters.
The big idea
The pipeline has three stages. Gateways accept the updates over a long-lived connection. A stream carries the updates, partitioned by driver or by geographic cell. A geo index service consumes the stream and keeps the latest state in memory. The matching service reads from that index, not from the database.
The index is fast and disposable. If it is lost, it can be rebuilt from the stream and driver reconnects. The trip database remains the source of truth.
Walking through it
The write rate. Take a region with about 1 million drivers, each reporting every 4 seconds:
1,000,000 drivers ÷ 4 seconds = 250,000 updates per secondWriting each update as a row in a relational database means 250,000 row updates per second, on the path that matching depends on. The design avoids that by keeping the latest state in memory. The durable record of a trip is written separately.
Two sets of drivers. Only available drivers belong in the matchable index. A driver is available when online, not on a trip, and matched to the right product and vehicle. On-trip drivers still send their location, so ETAs stay accurate. But they live in a separate set, so matching never offers them a trip.
Stale drivers. A driver who has not reported for a set time, such as 30 seconds, is removed from the available set. A tunnel or a dead phone should not leave a ghost driver in the index. Matching also skips any candidate whose timestamp is too old.
History. Breadcrumbs for analytics can flow into the same stream and then into cold storage. Matching does not read them.
Common mistakes
- Writing every ping to a row-based database. The write rate will outrun it.
- Keeping on-trip drivers in the matchable set. They get offered trips they cannot take.
- Matching on stale positions. Check each candidate's timestamp.
- Treating the location index as billing truth. It is fast and rebuildable, not a record of trips.
Check yourself
-
A region has 1 million drivers, each reporting every 4 seconds. How many updates per second arrive?
Answer: 250,000 (1,000,000 ÷ 4).
-
Why should on-trip drivers live in a different set from available drivers?
Answer: matching reads only the available set, so an on-trip driver is never offered a new trip. The location of on-trip drivers still feeds ETAs.
Key takeaways
- Location updates are the highest-volume traffic, so they flow through a stream into an in-memory index.
- The index keeps only the latest position, and it can be rebuilt if lost.
- Keep only available drivers in the matchable set, and remove drivers who go quiet.
- The trip database, not the location index, is the source of truth.
Further learning
Next, see how one driver is handed to exactly one rider, in exclusive driver assignment.
Related
Case study: ride-sharing
Uber-style dispatch: streaming driver locations into a geo index, matching under contention, trip state and geographic sharding. Start here for the ride-sharing map.
Geospatial indexes
How geohashes, quadtrees and H3 hexagons turn "who is near this point?" into a small set of cell lookups, and the boundary trap that catches naive geohash searches.
Event streaming and Kafka
How a durable log lets many consumers read the same events at their own pace, and how Kafka builds that log from partitions, replicas and consumer groups.
Real-time delivery
How a server pushes updates to clients that did not ask, from polling to WebSockets, and the gateway, pub/sub and reconnect design that serves millions of open connections. Start here for the real-time map.