System Design: Uber (Walnut Ride: H3 Driver Index, 2-Second Batch Matching, Leases and Fencing Tokens, One Charge per Ride)
We design a ride-hailing app as large as Uber. Our version is called Walnut Ride.
A rider asks for a ride. Within a few seconds, a free driver nearby gets the trip. The driver picks the rider up, drives to the drop-off, and the rider's card pays.
As in any system design interview, every number here is our own planning assumption, and the design is our own. All times are New York time.
How to read this post. It takes about 75 minutes in full, so it is built to be read in parts:
1. Requirements
1.1 What we are building
Walnut Ride does three jobs.
- It knows where every driver is. Each online driver's phone sends its position every 4 seconds.
- It matches. For each rider, it picks a free driver who can reach them quickly by road. It holds that driver for that rider alone.
- It runs the trip and the money. It tracks the car, ends the trip and charges the rider once. Then it pays the driver.
The story takes place on Friday 9 October 2026, in New York:
- 18:39:50. Emma is a nurse who has just finished a shift. She stands outside Penn Station and opens the app to go home to Park Slope, in Brooklyn. The app shows a fare of $40.00 plus tax, and a pickup in 4 minutes.
- 18:40:00. She taps Request. Her signal is weak, so the app sends the request twice. Walnut Ride saves one trip.
- 18:40:02. Mike drives for Walnut Ride and is free, three blocks away. He gets the offer for Emma's trip.
- 18:40:06. Mike taps Accept. Emma sees his car on her map.
- 18:41. Sarah and Jake ask for rides near Madison Square Garden. Daniel is the closest free driver for both. A matching server freezes for half a minute in the middle of its work. Daniel is still offered to only one of them, and Sarah gets another driver one batch later.
- 18:44. Mike reaches Emma. At 18:45 the trip starts.
- 18:55. Rain starts in Midtown. Many riders ask at once, and the price there rises to 1.4 times normal. Emma's price was fixed when she booked, so it does not change.
- 19:20. Emma arrives home. Her card pays $42.00 once, even though one call to the card company timed out and was sent again. Mike is owed $32.00.
- 21:15. One of the three data centers in our US East region fails. Olivia, the on-call engineer, watches some cities pause matching for about 12 seconds. No trip is lost.
The hard part is finding a free driver near Emma within 3 seconds while 416,000 driver positions arrive every second. And one driver must never be promised to two riders, even when a server freezes.
1.2 Words we use
Words used in only one place are explained there. Each word below is used all through the post.
Maps and places
| Word | Meaning |
|---|---|
| H3 cell | H3 is a way to cover the earth with hexagons. Each hexagon is a cell with its own ID. Uber made H3 and shared it as open source. |
| Resolution | The size of an H3 cell. Each resolution is about 7 times smaller than the one before. A resolution 8 cell is about 0.74 km², roughly a kilometer across. |
| Ring | The cells around a cell. Ring 1 is the 6 cells touching it. Ring 2 is the 12 cells around those. |
| Region, data center | A region is one area of the world where we run servers, such as US East. Each region has three data centers, a few kilometers apart. |
| Home region | The one region that runs a city's live work at any time. New York's home region is US East. |
| Backup region | The region that takes over a city when its home region is lost. US East's backup is US West. |
Matching and prices
| Word | Meaning |
|---|---|
| ETA | Estimated time of arrival: how long a car needs to reach a place by road, with today's traffic. |
| Batch, window | Riders who ask in the same 2 seconds are matched together. The 2 seconds are the window, and the riders in it are one batch. |
| Offer | A message to one driver: "here is a trip, accept within 15 seconds". |
| Surge | A higher price in an area where more riders ask than there are free drivers. "1.4x" means 1.4 times the normal fare. |
| Quote | The price and pickup time a rider sees before booking. It is signed, so nobody can change it, and it ends after 5 minutes. |
Changes that must happen once
| Word | Meaning |
|---|---|
| Idempotency key | A random ID the app makes once for one action, such as one booking. If the same key arrives twice, the second copy does nothing new. |
| Lease | A hold that ends by itself at a set time unless someone renews it or turns it into something else. |
| Fencing token | A number that goes up by one each time a driver is held for a new trip. A later step must show the current number, so an old step is refused. |
| Compare-and-set | A write that names what the row must still hold, such as "only if the state is still OFFERED". If the row changed, nothing is written. |
| Outbox | A small table in the Trip Store. Each trip change adds one row to it in the same transaction, and a separate program sends those rows on as events. |
| Workflow | A program that runs one trip's timers and payment steps. It saves each step, so another server can carry on after a crash. |
Money
| Word | Meaning |
|---|---|
| Hold, capture | A hold asks the rider's bank to set an amount aside. A capture takes the money. A hold that is never captured ends after about 7 days. |
| PSP | Payment service provider: a company that connects us to card networks and banks. |
| Ledger | Our record of all money. Each payment is a set of rows that add up to zero, and rows are only added, never changed. |
Servers and storage
| Word | Meaning |
|---|---|
| Shard | One slice of a store, kept on its own server. |
| Kafka topic, partition | Kafka is a log that keeps messages in order. A topic is one named stream, and a partition is one ordered slice of a topic. |
| p99 | The time that 99 of every 100 requests beat. It shows the slow cases. |
IDs in this post
Every ID below is made up for the story.
| ID | What it names | Example |
|---|---|---|
| T-NYC-8F2K41 | A trip ID. The city code comes first, so any server can tell the city without a lookup | Emma's trip |
| R-20931 | A rider ID | Emma |
| D-7781 | A driver ID | Mike; D-4410 is Daniel |
| Q-5Z1H7 | A quote ID | Emma's quote of $40.00 at 18:39:50 |
| 7b1e4c2a | An idempotency key, shortened here | Emma's booking; both copies carry it |
| 882a100d2dfffff | An H3 cell ID at resolution 8 | The cell outside Penn Station |
| token 9 | A fencing token, one driver's counter | Mike's hold for Emma's trip |
| epoch 7 | A city epoch: the count of times a city has moved to another region | New York before any move |
| M-9920 | A money order: one set of ledger rows that sum to zero | Emma's $42.00 |
1.3 Every kind of request and change
The story follows a few people. Walnut Ride handles much more than that. Each row names the part that handles it, and the outside company that takes part.
| Kind | What it is | How big or how often | Which part handles it | Outside company that takes part |
|---|---|---|---|---|
| Location point | A driver's position, time and free or busy status | 416,000 a second at peak | The Location Service, Kafka, the Index Writer and the Live Driver Index | None |
| Quote | A price and a pickup time before booking. Emma's at 18:39:50 is one | About 2,000 a second at peak | The Pricing Service, the ETA Service and the Surge Store | None |
| Ride request | A booking from a quote. Emma's at 18:40:00 is one | 870 a second at peak | The Trip Service and the Trip Store | None |
| Match and offer | A free driver picked and held for one rider, then asked | One batch every 2 seconds in each city | The Dispatch Service, the Trip Store and the Push Gateway | None |
| Driver answer | Accept, decline or no answer in 15 seconds | About one per offer | The Trip Service | None |
| Trip change | Arrived, started, ended | About 4 per trip | The Trip Service and the Outbox Relay | None |
| Cancel | By the rider or the driver, with a fee by the city's rules | A small share of trips | The Trip Service and the Workflow Engine | None |
| Tracking update | The car's position and a fresh pickup time for the rider | 100,000 pickup times a second at peak | Trip Tracking, the ETA Service and the Push Gateway | None |
| Payment | A card hold at booking, a capture at the end, refunds later | About 2 calls per trip | The Workflow Engine and the Payments Service | PSPs, such as Stripe or Adyen |
| Driver payout | Money owed to drivers, sent to their banks | Once a week, or on request | The Payments Service and the Ledger Store | Banks |
| Surge update | A new price multiplier for each area | Every minute | The Surge Service and the Surge Store | None |
| City setting change | Fares, surge cap, search distance, offer time | Thousands a week across all cities | The City Directory, which also holds each city's settings | City regulators set some limits |
This post follows Emma's ride, and the race for Daniel, in depth. The other kinds use the same parts.
1.4 Functional requirements
- Quote. Show a fare and a pickup time before booking, and hold that fare for 5 minutes.
- Book. Turn a quote into a trip. A repeated request books one trip, not two.
- Match. Pick a free driver near the rider, by road time to the pickup.
- Offer. Send the trip to one driver, who accepts or declines within 15 seconds. On a decline or no answer, try another driver.
- Driver location. While a driver is online, the driver app sends its position every 4 seconds.
- Tracking. The rider sees the car move on a map, with a pickup time that updates.
- Trip steps. The driver marks arrived, start trip and end trip.
- Pay. Charge the rider once at the end, pay the driver, and send both a receipt.
- Cancel. The rider or the driver can cancel. A fee applies by the city's rules.
- Surge. Raise prices where riders outnumber free drivers, within each city's legal cap.
- City settings. Each city has its own fares, surge cap, search distance and offer time.
Out of scope: shared rides, food delivery and rides booked for later. So are driver sign-up and background checks, building the road map, and training the price and ETA models.
1.5 Non-functional requirements
- Fast first offer. A driver gets the offer within 3 seconds of booking at p99, when a free driver is near.
- Fast answers. A quote takes under 300 ms and a booking under 500 ms at p99, inside our servers.
- One rider per driver. A driver is held for one trip at a time, through any server freeze or failover.
- A booked trip stays booked. Once the rider has a trip ID, the trip survives the loss of a whole region.
- One charge. A retried payment call never charges a card a second time.
- Always on. Each city accepts ride requests 99.99% of each month, about 4.3 minutes of downtime.
- Data center loss. If one of a region's three data centers fails, its cities pause matching for about 12 seconds.
- Region loss. If a whole region fails, matching restarts in the backup region within 5 minutes.
- A live map. The car moves on the rider's map every 4 seconds, and the pickup time updates every 10 seconds.
- Live state may be rebuilt. Driver positions, waiting riders and surge may be lost in a failure. They rebuild within a minute.
- Legal prices. No fare goes above the city's surge cap.
1.6 The numbers
These are rough sums, the kind a candidate does at a whiteboard in a few minutes. Every number is our own assumption.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Ride requests | 25 million rides a day ÷ 86,400 seconds = 290 rides a second. The busiest hour is 2.5 times the average: 720 rides a second. Some requests never become rides, so 1.2 requests a ride | 870 requests a second at peak | One ordinary transactional database could take this many bookings. So the design effort goes to the location points |
| Drivers online | Little's law: drivers busy at once = rides started a second × minutes each ride keeps a driver busy. 23 minutes is 1,380 seconds, so 720 × 1,380 = about 1 million busy. If 60% of online drivers are busy, 1 million ÷ 0.6 | 1.66 million drivers online | Every one of them sends positions, so the location load is the big one |
| Location points | 1.66 million drivers ÷ one point every 4 seconds | 416,000 points a second | Each point replaces the last one within seconds. So positions live in memory behind a log, never in a database on disk |
| Index work | One driver move costs about 20 µs of Redis time. 416,000 × 20 µs = 8.3 seconds of work each second, which keeps 8.3 cores busy. One Redis shard runs on one core, planned at 60% busy: 8.3 ÷ 0.6 = 14 | 14 shards' worth of work | No single Redis server can take it, so the index is split. A pickup search never leaves its city, so each city's keys go to one shard |
| Biggest city | We give the biggest city 4% of rides: 4% × 720 = 29 rides a second. × 1.2 requests, plus a sharper local peak, is about 40 a second. 40 × 2 seconds = 80 riders a batch. Its drivers send 4% of the points, about 20,000 a second | 80 riders in a 2-second batch; 0.4 of one core | The solver handles a batch this small in about a millisecond. The whole city fits on one index shard |
| ETA requests | Tracking: 1 million busy drivers, and each rider gets a fresh time every 10 seconds = 100,000 a second. Real route searches: about 2,000 quotes plus 870 matches = about 2,900 a second | 100,000 times and 2,900 searches a second | The 100,000 cars are already on a route and need no search. So we route once and then add up the road pieces left |
| Trip rows | 25 million trips a day × about 2 KB for the trip, its changes and its outbox rows | 50 GB a day; 4.5 TB for 90 days | The Trip Store keeps 90 days. Older trips move to the data lake, so the store copied across regions stays small |
| Cross-region commit | A trip write must reach a second region before it counts. Between US East and US West, one round trip is about 70 ms, and about 130 ms at p99 | About 130 ms a write at p99 | A booking with two writes still fits under 500 ms. A design that needs several rounds across regions does not |
What these numbers tell us: the bookings are small, but 416,000 positions arrive every second. So positions live in memory, split by city. Trips are few and precious, so they go to a slower store that copies each write to a second region.