How to design Uber
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Taking in driver locations
- Never two rides for one driver
- Surges and geo-sharding
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
A ride-hailing app takes a rider's pickup and destination, quotes a fare, and hands the request to a nearby driver who can accept or decline. Two forces shape the design. Drivers report where they are every few seconds, so position writes dwarf the rest of the traffic and need a store built for fast overwrites rather than history. And a driver can hold one ride at a time, so the matching step has to reserve a driver before offering, survive a crash mid-offer, and move on when nobody answers. The rest of the system (fares, ride records, push notifications) is ordinary request handling that hangs off those two paths.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
How many drivers are online, and how often does each one send its position? | The product of those two figures is the write rate on the position store, and it decides whether a normal database is even a candidate. | About 10 million drivers online, each sending a position roughly every 5 seconds, about 100 bytes an update. That's roughly 2 million updates a second. |
How fast does a rider need a match, and what happens when there is no driver? | A time budget tells you how long each offer may wait on a driver, and how many drivers you can try in sequence before you give up. | A match, or a clear failure, within a minute. Report no driver found rather than leaving the rider waiting. |
Can a driver ever be offered or assigned two rides at the same time? | If not, matching needs a reservation step, and the interesting question becomes where that reservation lives and what happens when that store fails. | No. A driver holds at most one ride. Design for that even when the piece that tracks busy drivers is down. |
What does peak demand look like, and is it spread out or concentrated? | Concentrated spikes (a stadium, a concert) are harder than spread-out load because they land on one region's drivers and one region's shard. | Up to 100,000 requests from the same few blocks within minutes after a big event lets out. |
Do we need surge pricing, ride categories, scheduled rides or payments? | Each is a product on its own. Knowing they're out lets you spend the hour on locations and matching. | Payments, ratings, scheduled rides and categories are out of scope. Surge pricing is a reasonable extension if time allows. |
Is the fare fixed once quoted, and how long is a quote good for? | A fixed quote means the ride request carries a fare id and the server looks the price up, instead of trusting a price in the request body. | Yes, the quote is fixed for a short window. The ride request references the fare by id. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
A match in under 1 minute, or a clear failure | The nearby search has to come out of memory, and each offer gets a short accept window so several drivers can be tried in turn inside the minute. A request that runs out of drivers returns a failure to the rider instead of hanging. |
A driver is never assigned two rides at once | A reservation before each offer, held in a store the matching service checks before it offers, and a conditional write on accept so a stale accept is rejected. The design also needs an answer for the reservation store itself failing. |
Handles 100,000 requests from one place at peak | Ride requests wait in a region-partitioned queue, so a spike queues rather than drops, and a hot region can be split into more partitions, each with its own matcher, without touching the others. |
Takes about 2 million driver location updates a second | Positions go to a geo index held in memory that overwrites each driver's latest point, not to the rides database. The client sends less when the driver is idle, and a sweep removes drivers that have gone quiet. |
Estimates
| Quantity | Working | Result | What it sizes |
|---|---|---|---|
Location writes a second | 10 million drivers ÷ 5 seconds between updates = 2,000,000 updates a second | About 2 million updates a second | The write rate the position store must take, which rules out a row-per-update relational table. |
Memory for the latest position of each driver | 10 million drivers × about 100 bytes = 1,000,000,000 bytes | About 1 GB | The in-memory geo index: one entry per driver, overwritten on each update, fits on one large node with room to spare, before replicas and sharding for throughput. |
Inbound bandwidth of position updates | 2,000,000 updates a second × 100 bytes = 200,000,000 bytes a second, about 200 MB/s, or about 1.6 Gbit/s | About 200 MB/s | The network into the location service: spread across many instances, not one box. |
Rows a day if each update were kept | 2,000,000 a second × 86,400 seconds a day = 172,800,000,000 rows a day; at 100 bytes each, about 17 TB a day | About 173 billion rows and 17 TB a day | Why the history of positions is not stored in the main database: a relational table would have to index that many inserts, and a cloud table that bills per write would bill for each of those rows. |
Writes a second if drivers sent once a minute | 10 million drivers ÷ 60 seconds = 166,667 a second | About 167,000 writes a second, a twelfth of the base rate | What the client-side knob is worth: slowing the update interval cuts writes in proportion, at the cost of staler positions. |
Example: half the drivers idle and sending every 30 seconds | 5 million moving ÷ 5 seconds = 1,000,000; 5 million idle ÷ 30 seconds = 166,667; total about 1,166,667 | About 1.17 million writes a second, about a 40% cut | An illustration of adaptive update intervals; the share of idle drivers is an assumption, not a target. |
Offers that fit inside the match budget | 60 seconds ÷ 10 seconds an offer = 6 offers | About six drivers if each one uses the full offer window; quick declines leave room for more | The offer loop when drivers go silent: roughly six full timeouts fit in the minute, so after that many silent offers the request should fail clearly, or the design should offer to several drivers at once. |
Match rate during a concert surge | 100,000 requests over about 5 minutes = 333 a second; over 1 minute = 1,667 a second | Roughly 300 to 1,700 matches a second in one region, on the assumption that the requests arrive over one to five minutes | The consumer capacity one region's queue partition needs during a spike, and how deep the queue gets if matchers fall behind. |
Core entities
| Entity | What it holds |
|---|---|
Rider | The person asking for a ride. Identified from the auth token on each call, not from the request body. |
Driver | A driver account plus a status that says whether they can take an offer. The latest position lives in the geo index, not here. |
Fare | A priced quote for a pickup and destination, valid for a short window. The ride request points at it instead of carrying a price. |
Ride | One row per request, moving through a status machine from requested to completed or canceled. |
Location | A driver's latest point. Kept in the in-memory geo index, overwritten on each update, with a timestamp for the sweep. |
The API
| Endpoint | Notes |
|---|---|
| The ride service calls a maps provider for distance and time, prices the trip, stores the fare with an expiry and returns it. The rider comes from the token. Rate-limit it per rider: in this design each call reaches the maps provider, so unchecked callers run up that bill. |
| Looks the fare up, checks it belongs to this rider and hasn't expired, inserts a ride in status requested and publishes it to the region's queue. Returns at once; in this design the rider is told of the match later through the notification service. Sending a price in the body is the classic mistake. |
| The hot path: about 2 million calls a second across the fleet. The gateway authenticates, the location service overwrites the driver's point in the geo index and refreshes its timestamp. No database write. The app can call it less often when the driver is idle. |
| Accept is a conditional write: ride status requested to accepted and driver status to on_trip in one transaction, guarded on the ride still being unassigned; a late accept gets |
The high-level design
Step 1 of 4
Fare and ride request
Start with the rider's path. The rider app calls an API gateway that checks the token and rate-limits, then a ride service. POST /fare asks a maps provider for distance and time, prices the trip and stores a fare with an expiry; POST /rides turns a fare id into a ride row in status requested. Fares and rides live in one relational database: they're small, low-rate and need transactions later for accept. The rider's id comes from the token on both calls, and the price comes from the stored fare, so the client can't set either.
What breaks first
The deep dives
Taking in driver locations. About 10 million drivers each send a position every 5 seconds, and riders keep asking who is nearby. Where do those writes go, how is a nearby-driver search answered, and how do you keep drivers who went offline from being matched?
Never two rides for one driver. Two riders on the same street request in the same second and one driver is closest to both. How does the system make sure that driver gets one offer at a time, and what happens when the driver ignores it, when the matcher crashes mid-offer, or when the store that reserves drivers is down?
A concept that helps here: State machines in database rows
Surges and geo-sharding. A concert lets out and 100,000 riders request from the same few blocks within minutes. Which part fails first, what happens to requests in flight when a matcher crashes, and how do you scale matching and locations for one hot region?