Design Case StudiesExpert16 min read2 questions

Design a Ride-Hailing System (Uber / Lyft)

Real-time geospatial matching. How to index a moving fleet, find nearby drivers in milliseconds, and run a matching algorithm that is correct under heavy concurrency.

Covers: Geospatial indexing, driver location updates, matching, surge pricing, trip state machine, ETA

Ride hailing is the best case study for geospatial systems and for concurrency: two riders must never be matched to the same driver, and 'find drivers near me' must run in milliseconds against a fleet whose positions change every four seconds.

  • Scale: 5 M active drivers, 20 M daily rides, peak 500,000 concurrent trips.
  • Location updates: 5 M drivers × every 4 s ≈ 1.25 M writes/s. This is the dominant write load in the system.
  • Matching: find drivers within a radius and assign one, in under 2 seconds end to end.
  • Correctness: a driver may be assigned to exactly one trip. This is a hard constraint, not a best effort.
Filter
0/2 mastered
ExpertgeospatialgeohashindexingAsked at Uber, Lyft

30-second answer

Use a grid-based spatial index that turns a two-dimensional proximity query into a one-dimensional key lookup. Geohash or Uber's H3 hexagonal system encodes a location into a cell identifier, so 'nearby' becomes 'in this cell or its neighbours' - a handful of key lookups rather than a scan. Keep live positions in memory in Redis rather than a database, because at 1.25 million writes per second the durability of each individual position is worthless: a position four seconds old is already stale, so losing it costs nothing.

Expertconcurrencymatchingstate machineAsked at Uber, Lyft

30-second answer

Make the assignment an atomic compare-and-set on the driver's state: transition from `available` to `offered` only if the current state is `available`, so exactly one rider wins and the other immediately gets the next-best driver. Never do a read-then-write. Model the trip as an explicit state machine with allowed transitions and enforce them in the database, and give every offer a short expiry so a driver who does not respond within a few seconds releases automatically rather than being stuck.

Showing 2 of 2 questions for design-a-ride-hailing-system.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.Why does Uber's H3 use hexagons rather than squares?

Question 2

2.Which correctly prevents two riders being matched to the same driver?

Question 3

3.Should every driver location update be written to a durable database?

Question 4

4.Why must a ride offer have a short expiry?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Design the matching service

Handle 1.25 million location updates per second and match riders to drivers in under two seconds, correctly under concurrency.

Requirements

  • Choose a spatial index and resolution, and justify both against candidate-set size and boundary crossings.
  • Design the location write path and state exactly what is and is not persisted.
  • Write the atomic assignment query and prove it is race-free.
  • Define the full trip state machine with guards, timeouts and cancellation rules.
  • Design surge pricing as a smoothed, capped control loop with price locking at request time.

Stretch goals

  • Implement batch matching over a 3-second window and compare wait times against greedy assignment.
  • Handle a stadium emptying: 50,000 requests from one cell in 60 seconds.