Skip to content

How to design Uber

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

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

AskWhy it mattersA 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.

The requirements menu

RequirementScopeWhy

A rider enters pickup and destination and gets a fare estimate

Core

The first screen of the product. It needs a call to a maps provider for distance and time, and a stored fare the ride request can point at.

A rider requests a ride at that fare

Core

Creates the ride record and starts matching. The rider comes from the token and the price from the stored fare, so the client can't change either.

The rider is matched with a nearby available driver

Core

The heart of the question: a nearby-driver search over live positions, then a reservation so the driver is offered one ride at a time.

A driver accepts or declines, then navigates to pickup and drop-off

Core

Closes the loop. Accept records the driver on the ride and marks that driver busy in one transaction; decline or silence passes the offer along to another candidate.

The rider sees the assigned driver moving toward them on a map

Optional

Worth taking if asked: the positions already flow in, so it's a read of one driver's latest point pushed to one rider. Leave it unless the interviewer wants a real-time channel discussion.

A rider cancels a request before or after a match

Optional

Cheap to add on the ride record (a status transition) and it tests whether a canceled ride frees the driver. Mention it, build it if time allows.

Surge pricing by area when demand outruns supply

Optional

Tempting in the surge deep dive: raising prices is one way to bring requests back to what drivers can serve. It's a pricing system of its own, so name it as a lever and don't design it.

Ride history and receipts for riders and drivers

Out of scope

Reads of finished ride rows. Nothing in the matching path depends on it.

Fraud detection and spoofed driver positions

Out of scope

Real in production, but a separate pipeline over the same position stream. Say where the stream could be tapped and move on.

Ratings of riders and drivers

Out of scope

Ordinary writes after a ride ends. They don't touch the location or matching path.

Scheduled rides

Out of scope

A scheduled ride is a ride request fired later by a timer. The matching path is the same, so skip the scheduler.

Ride categories such as X and XL

Out of scope

Categories become a filter on the nearby-driver search. Easy to add, not worth the time in the round.

Payments

Out of scope

Charging a card after a ride is its own system with its own consistency problems. Park it.

Non-functional requirements

RequirementWhat 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

QuantityWorkingResultWhat 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

EntityWhat 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

EndpointNotes

POST /fare { pickup, destination } → Fare

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.

POST /rides { fare_id } → Ride

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.

POST /drivers/location { lat, long } (driver from the token)

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.

PATCH /rides/{id} { accept or decline }

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 409 Conflict. Decline, or a timeout, moves the offer to the next driver.

The high-level design

requestsRider appAPI gatewayRide serviceDatabase

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.

POST /fare,/ridesPOST/drivers/locationfares, ridesby regionGEOADDremove quietcommit aftermatchGEOSEARCHSET NX, shortTTLofferaccept timeoutRider appAPI gatewayDriver appRide serviceLocation serviceRides databaseRide requestqueueRedis GEO: latestpositionsStale driversweepMatching serviceDriver locksNotificationserviceDurable workflow
The whole design

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?

A concept that helps here: Geospatial indexingA concept that helps here: Heartbeats and presenceA concept that helps here: Back-of-the-envelope estimation

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: Distributed locks and leasesA concept that helps here: Job scheduling and delayed work

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?

A concept that helps here: Sharding and partition keysA concept that helps here: Delivery semantics: at most, at least, exactly onceA concept that helps here: Hot keys and hot partitions

Concepts this guide uses

Sources

  1. Redis: Geospatial data type
  2. Redis: Distributed locks with Redis
  3. Redis: Replication
  4. High Scalability: How Uber scales their real-time market platform
  5. Uber Engineering: H3, Uber's hexagonal hierarchical spatial index
  6. Conduktor: Kafka delivery semantics for consumers
  7. Temporal: Timers (TypeScript SDK)
Sign in to report a mistake