Case study · Mobility · complexity 4/5
How a ride-hailing app finds the right nearby driver in seconds — from one SQL query in one city to in-memory hexagon cells, batched matching and trips that survive the loss of a region, with Uber's published H3 and engineering posts as the documented examples
This is an educational reference architecture, not the design of Uber, Lyft or any other company. Where we cite a company's own published material (Uber's H3 documentation, engineering posts and marketplace pages), or notes of a conference talk, it is marked as documented.
In one city, a ride request runs one query: available drivers within 2 km of the pickup, nearest first. A spatial index answers it in milliseconds.
Architecture evolution
Driver apps write their position to a drivers table every few seconds. A ride request runs one query, "available drivers within 2 km, nearest first", using PostGIS's ST_DWithin on a GiST index, and the server offers the trip to the nearest driver.
Components
What breaks next
Writes, not reads. Every online driver rewrites a row and its index entry every few seconds, so the main database spends its effort on positions that are stale moments later, while both apps poll it for news.
App server
dashboard
Query planner
picks a strategy
B-tree index
orders.created_at
orders table
50M rows · 600,000 pages
Swipe the diagram sideways to see every column →
Where the time goes
6542 ms total
A dashboard runs SELECT * FROM orders WHERE created_at >= now() - interval '7 days' on 50 million orders (about 600,000 pages). About 1% of rows match. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.
Uber has published how it divides cities into hexagons, why it batches matches for a few seconds, how surge follows supply and demand in each area, how its apps receive pushed updates, and why it moved the platform behind its trips and deliveries to a strongly consistent database. Those posts and pages are the documented part of this case study; the architecture around them is our educational design.
What Uber has published about dispatch
A rider expects a car within seconds of tapping the button, every driver's position changes every few seconds, and the same driver must never be promised to two riders. Each of those pressures breaks a naive design in a different place.
Six pressures on a dispatch system
In one city, a ride app can run on one PostgreSQL database with the PostGIS extension: each driver's latest position is a row, and a request asks for available drivers within 2 km, nearest first. PostGIS's documented ST_DWithin and GiST index make that query fast; the design around them is our educational sketch.
Stage 1: one database answers every question
The bottleneck moves from database writes in one city, to crowded cells and live connections across many cities, to correctness and survival when there are many regions. The traffic numbers in this section are illustrative.
The bottleneck moves at each stage
A driver's position is useful for a few seconds and then replaced, so it belongs in memory, filed by area, with a copy flowing to an event stream for history, not in the database that holds trips and payments. Notes of a 2015 Uber talk report drivers sending a location every 4 seconds.
One location update, two destinations
To find nearby drivers without measuring the distance to every driver, the map is cut into cells and each driver is filed under one; a search then reads only the cells around the pickup. Geohash cuts the map into rectangles, while H3, which Uber open-sourced in 2018, uses hexagons whose six neighbors are all the same distance away.
Squares have two kinds of neighbor, hexagons one
Three H3 resolutions a city might use
Matching is a short optimization, not a lookup: candidates from nearby cells are ranked by ETA along roads, and requests that arrive within a few seconds are assigned together so the total wait is lowest. Uber documents both ideas: the closest car is not always the quickest, and it batches requests for a few seconds.
Nearest-first versus a two-second batch
Once a driver accepts, the rider watches the car approach and the driver gets offers and changes, so the server must push updates within a second or two instead of waiting to be asked. Uber documented that polling once made up 80% of requests to its API gateway, before it built a push platform.
Pushing trip news to both apps
The in-memory index is split into shards by city, and large cities by groups of cells, so each shard holds one area's drivers. That works until a stadium empties after a match and thousands of riders and drivers pile into the same few cells on one shard.
A stadium turns one shard hot
Surge pricing is computed separately for each small area: when open requests in a cell outnumber available drivers, the price there rises to draw drivers in and spread demand out. Uber documents that it measures supply and demand in hexagons and that high demand in one area does not change prices in another.
Prices from counts per cell
A trip must never have two drivers and a driver must never hold two trips, even when two matchers, a retry and a flaky network act at once. In our design, each change to a driver's or a trip's state is a compare-and-set on a versioned record, and every accept carries an id that makes repeating it harmless.
Two matchers, one driver, one winner
When a whole cloud region fails, trips already under way must carry on: the rider is in the car and the fare must still be right. Hard state (trips, accepts, quotes) must already exist in another region, while soft state (positions, connections, the cell index) is rebuilt there within seconds from the phones' next messages.
What survives a region failure, and how
Uber's published material traces the path from a 2015 dispatch system built on S2 cells and a gossip ring, through H3 in 2018, to pushed updates in 2020, a strongly consistent trip store in 2021 and learned ETAs in 2022.
Uber's published milestones in dispatch
At global scale, positions take a fast, lossy path into memory, matching and pricing read from it, and trip state takes a slow, strict path into a replicated store. This is a typical educational design, not a diagram of Uber's, Lyft's or any company's system.
A fast path for positions, a strict path for trips
Every choice in dispatch trades the rider's wait, accuracy or cost against another: batching adds seconds to save minutes, finer cells add reads, frequent updates cost battery and servers, and strict trip state adds latency. The dials are set per city and per situation, not once.
Five dials for a dispatch system
On a bad night, five things typically go wrong: a stadium empties, a driver vanishes into a tunnel, an accept races a cancel, a push gateway deploy drops connections, and a region fails mid-trip. Each needs a response designed before it happens.
A bad night for dispatch, five ways
Four simulations show the building blocks this case study depends on: pushing updates instead of polling, a hot key on one shard, two requests racing for one thing, and losing a whole region. All timings and loads are illustrative models.
Your phone
score page open
App server
scores.example
Score feed
at the ground
Swipe the diagram sideways to see every column →
Where the time goes
30738 ms total
Your phone shows 120/2. In the next 30 seconds there is a four, a wicket and a six. Compare three ways of keeping the screen up to date. In the time bar, Screen out of date is time a new score sat on the server while your screen still showed the old one. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.
Swipe the diagram sideways to see every tier →
Busiest shard
0%
Errors
0%
p95 latency
0 ms
Served
0/s
Survive the celebrity
With the celebrity getting 40% of traffic, keep the busiest shard under 70% and errors under 0.5% for 15 seconds.
A social app shards posts by a hash of the user id across 4 shards, each good for about 2,500 queries per second. One celebrity account gets 40% of all reads — and all its rows live on one shard. All numbers are an illustrative model.
Illustrative model: rates, queues and latency follow simple queueing rules, not a production benchmark.
Request A
Priya buys
Database
tickets: stock = 1
Request B
Rahul buys
Swipe the diagram sideways to see every column →
Where the time goes
4 ms total
One seat is left (stock = 1). Priya and Rahul press Buy at the same moment, so two requests run the same code: read the stock, and if it is above zero, write stock − 1 and create an order. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.
Users
shoppers
On-call and automation
runbook
DNS
shop's address
Region A
primary
Region B
recovery region
Swipe the diagram sideways to see every column →
Where the time goes
172 min total
A shop runs its app and a 400 GB primary database in Region A. Nightly 02:00 backups are copied to Region B. At 09:00 the whole of Region A goes dark. All durations are illustrative.
Illustrative timings. Real numbers vary with distance, network quality and server load.
The H3 grid, Uber's batching, surge per area, ETAs in matching, its push platform, its move to a strongly consistent trip store, Redis geo commands and PostGIS behavior are documented in the sources. The three stages, every traffic number, the matching algorithm, the surge formula and the failover sequence are our educational assumptions.
Where the evidence stops