LOAD-BEARINGfree
Architecture labTier 13 · unit 5 of 31

Ride hailing

Riders request a ride from a location. The system finds nearby available drivers, offers the trip, and tracks the vehicle live until drop-off.

Envelope1M drivers · location ping every 4s · match in < 5s

What the design must do

  • Ingest a location ping per driver every few seconds
  • Find available drivers near a point, fast
  • Assign one driver to one rider with no double-assignment
  • Stream live location to the rider

The worked envelope

Assumed. 1M active drivers, a location ping every 4 seconds, 100k ride requests in the peak minute.

Worked envelope
Location writes1M ÷ 4 s = 250k writes/s, sustained
Ping payloadid + lat/lng + heading + timestamp ≈ 40 B
Ingest bandwidth250k × 40 B = 10 MB/s
If persisted raw250k/s × 40 B × 86,400 = 864 GB/day
Live map in RAM1M drivers × 64 B = 64 MB
Match requests100k/min = 1.7k/s at peak

What the numbers decide. Put the two most distant lines side by side. Raw location history is 864 GB a day. The current position of every driver on the platform is 64 megabytes — it fits in the memory of a laptop, several times over.

That gap is the entire architecture. Only the current position is needed to answer "who is near this rider", so the hot path is an in-memory geospatial index that never touches disk, while the 864 GB/day of history is a completely separate, downsampled, append-only concern with no latency requirement at all. Writing every ping to your operational database is the mistake this envelope exists to prevent — it is 250k writes/s against a store that also has to serve matching.

The decisions, and what each one costs

Current driver positions in an in-memory geospatial index, keyed by cell

Because
The live map is 64 MB and the query is always "who is in these cells", so proximity becomes a key lookup rather than a distance calculation over a million rows
The cost
The index is volatile — a restart loses it, and it must be rebuilt from the next round of pings
Rejected
Geospatial queries against the operational database, which is 250k writes/s and an O(n) scan competing with matching

Downsample the location trail before persisting it

Because
864 GB/day of raw pings buys nothing the product uses; billing and disputes need a route, which survives keeping one point in ten
The cost
Fine-grained replay is gone — you cannot reconstruct exactly what the app saw at 14:03:07
Rejected
Persisting every ping, which is a time-series ingest problem bolted onto a matching system for no product reason

Dispatch as the only component with a global view

Because
Matching is a scheduling decision across many riders and drivers at once; a car that knows only about itself cannot avoid two riders being offered the same driver
The cost
A central component on the critical path, which must be partitioned by geography to scale and is a failure domain
Rejected
Drivers claiming requests directly, which is a distributed race with real-world consequences

Accept a stale position of a few seconds in matching

Because
A 4-second ping interval means the data is already up to 4 seconds old, so demanding freshness beyond that is demanding precision the sensor never had
The cost
Occasionally dispatching to a driver who has just moved out of range
Rejected
Higher ping frequency, which multiplies a 250k/s write rate to buy accuracy the matching window does not need

Components in the reference design

Client
Browser or mobile app
Load Balancer
L7 routing, TLS termination, health checks
App Service
Stateless business logic
Geo Index
Geohash / H3 cells for proximity
Cache
Redis / Memcached, sub-ms lookups
SQL DB
Relational, ACID, joins
Queue
Work distribution, one consumer per message
WS Gateway
Holds persistent client connections

The reference design

The location firehose. A million drivers pinging every 4 seconds is 250k writes per second of data that is worthless 10 seconds later. Do not put it in your transactional database. Current location lives in memory (Redis with geospatial commands, or a dedicated in-memory geo service); the durable trip record goes to the relational store only at state transitions.

Geospatial indexing. Comparing the rider's position to every driver is O(n) per request and dies immediately. Encode 2D position into a 1D cell ID — geohash, S2 or H3 — so that spatial proximity becomes key proximity. "Drivers near me" becomes "drivers in my cell plus the eight neighbouring cells," which is a handful of set lookups.

Neighbours matter: a rider standing just inside a cell boundary would otherwise miss a driver 20 metres away in the adjacent cell. Choose cell size so a typical cell holds tens of drivers, not thousands — too coarse and you scan too many, too fine and you query too many cells.

Matching without double-assignment. This is a distributed locking problem. Candidate drivers are ranked by ETA (road distance, not straight-line), then offered the trip one at a time or in a short cascade. The assignment must be an atomic conditional write — set driver state to assigned only if currently available — so two simultaneous riders cannot both win the same driver. Offers expire, and an unanswered offer moves to the next candidate.

Live tracking is a WebSocket stream from the driver's pings to the rider, routed through the same connection registry pattern as chat.

Surge pricing is a stream job aggregating supply and demand per cell over a rolling window, writing a multiplier per cell that the pricing service reads. It is naturally a separate, asynchronous system.