System Design Playbook
11 · System designs100 users → 100M+ users14 min read

Design Uber (ride hailing)

Match riders with nearby drivers in seconds while millions of drivers report their location every few seconds. The core problems: storing and searching live locations, matching by ETA, surge pricing and a trip state machine you can trust with payments.

In one sentence

Keep live driver locations in an in-memory geo index, match by ETA in the rider's area, track every trip as a state machine in a durable database, and stream GPS pings for everything else.

A reference design: it covers what an app like this needs and follows how these companies have described their systems publicly, simplified to be learnable.

Requirements

Functional

  • Rider sees a fare and requests a ride
  • Nearby driver gets the offer and accepts
  • Both follow each other live on the map
  • Payment when the trip ends, ratings

Non-functional

  • Match in seconds
  • Very high write rate of GPS updates
  • Never lose or double-charge a trip
  • Highly available: a down region strands people

Back-of-the-envelope estimates

MetricEstimate
Drivers online at peak~5M, each pinging every 4 s → ~1.25M location writes/s
Trips~25M / day ≈ 300 trips/s created
Location record~100 B → only ~500 MB to hold every driver's current position: it fits in memory
History of pings~100 TB / year if you keep them all: a stream, not the main DB

The striking number is the location write rate. That's why current positions live in memory and only trips go to a durable database.

API and data model

POST /fare-estimates   { pickup, dropoff }          → { fareId, price, surge }
POST /rides            { fareId }                    → { rideId, status }
WS   driver → location { lat, lng, heading, ts }     every ~4 s
WS   rider  ← ride.update { driverLocation, eta, status }
POST /rides/:id/accept (driver)

trips(id, rider_id, driver_id, status, pickup, dropoff, fare, created_at)
drivers_now: driver_id → (lat, lng, status)          -- in-memory geo index

Architecture

Architecture
Scale
Follow a request
◱Rider app◱Driver appGPS every ~4 s⇄API gateway⚙Dispatchmatching⚙Location serviceGPS ingest⚙Pricingfare + surge⚙Trip servicestate machine☰Location streamKafka◎PaymentsStripe / Adyen⛁PostgreSQL+ PostGIS◎Maps & ETArouting engineϟGeo indexRedis GEO

Step by step · Request a ride

  1. 01Sets pickup and destination, sees the fare
  2. 02POST /rides
  3. 03Fare estimate × surge for this area
  4. 04Looks for drivers nearby
  5. 05GEOSEARCH: available drivers within 3 km
  6. 06Real ETA for each candidate
  7. 07Offer to the best driver: 15 s to accept
  8. 08Trip created: accepted
  9. 09Trip saved
  10. 10"Your driver is 4 min away"

At this scale · 1M users

Separate services for location, matching and trips

  • ▸Location service ingests GPS pings and streams them through Kafka
  • ▸Dispatch matches riders and drivers using ETAs, not straight-line distance
  • ▸Pricing computes surge per area from supply and demand

Tap any box to see what it does.

Deep dive: finding drivers nearby

"Drivers within 3 km" can't scan millions of rows. You need a spatial index that divides the map into cells:

TechniqueHow it worksUsed for
GeohashEncodes lat/lng as a string; nearby points share a prefixSimple radius search in Redis or a DB
QuadtreeRecursively splits busy areas into 4 smaller squaresAdapting to dense cities vs empty countryside
H3 (hexagons)Uber's hexagonal grid: every neighbour is at the same distanceMatching, surge areas and sharding by cell

Straight-line distance lies: the closest driver might be across a river. Dispatch takes a handful of candidates from the index and asks the routing engine for real ETAs before choosing. The offer goes to one driver with a timeout; if they don't accept, the next one gets it.

How it changes with scale

Architecture
Scale
Follow a request
◱Rider app◱Driver appGPS every ~4 s⚙App servertrips + matching◎PaymentsStripe / Adyen⛁PostgreSQL+ PostGIS◎Maps & ETArouting engine

Step by step · Driver location update

  1. 01Sends lat/lng every ~4 seconds
  2. 02UPDATE drivers SET location = …
  3. 03Spatial index updated

At this scale · 100 users

One app with a geo query

  • ▸Drivers send their position; it's saved in PostgreSQL + PostGIS
  • ▸Matching is a query: nearest available drivers within 3 km
  • ▸The rider's app polls every few seconds for the car's position

Tap any box to see what it does.

UsersWhat you runWhy it changes
100App + PostgreSQL/PostGIS, pollingA spatial index query is fast enough for a few drivers
10KRedis geo index, WebSockets, LBGPS writes would overload the main database
1MLocation, dispatch, pricing and trip services + KafkaEach part has a very different load and failure profile
100M+Geo index and trips sharded by area (H3), active-active regionsCities are independent: shard by geography and survive region failures

Key takeaways

  • 01Current locations are a high-write, in-memory problem; trips are a durable, transactional one.
  • 02Use a spatial index (geohash, quadtree, H3) and refine candidates with real ETAs.
  • 03Push live updates over persistent connections instead of polling.
  • 04Geography is a natural shard key: cities rarely interact.

Check your understanding

1 of 3

In a ride-hailing app like Uber, where do live driver locations live?

Security PlaybookNow attack it: threat-model this designFind the STRIDE threats in this architecture and pick the mitigations.↗