Case study V.9Advanced

Design a Ride Sharing App Like Uber

Two hard problems in one: absorbing a firehose of GPS updates, and matching each rider to exactly one nearby driver within seconds.

The short answer

Requirements. Drivers share their location while online, riders see nearby cars and an arrival estimate, and a ride goes from request to match, live tracking and fare; a match takes a few seconds, no driver is ever assigned to two riders, and a failure in one region leaves the others running.

Location updates
250,000 per second1M drivers, one every 4 s
Ingest
about 25 MB/s100 B per update
Ride requests
about 115 per secondpeak about 600

The design. Driver locations go to an in memory index of geohash or H3 cells sharded by city, and to a stream such as Kafka for history, never to one database row per driver. Matching takes the available drivers in the rider’s cell and its neighbors, ranks them by arrival time on the road graph, and offers the ride to one driver at a time with a 10 to 15 second timeout. A compare and set on the driver’s status makes a double assignment impossible, and during the trip the driver’s position reaches the rider over a WebSocket.

Interview prompt

Design Uber: a rider requests a ride, the system finds a nearby driver, and both follow the trip live on a map.

Requirements and estimates

Functional requirements

  • Drivers share their location while online.
  • Riders see nearby cars and an arrival estimate.
  • Request, match, accept; live tracking; fare at the end.

Non-functional requirements

  • Match within a few seconds.
  • Never assign one driver to two riders.
  • Absorb hundreds of thousands of location updates per second.
  • A failure in one region does not affect others.

Estimates

Location    1M drivers online × 1 update per 4 s = 250,000 writes/s
Ingest      250,000 × 100 B                       ≈ 25 MB/s
Ride asks   10M rides per day                     ≈ 115/s, peak ≈ 600/s

API and the driver state machine

API

PUT  /v1/drivers/me/location
     { lat, lng, heading, ts }
POST /v1/rides { pickup, dropoff }
→ 202 { rideId }
WS   /v1/rides/{id}/stream
→ driver position, ETA

Driver state machine

AVAILABLE → OFFERED → ON_TRIP → AVAILABLE
               │
               └ timeout or decline → AVAILABLE

/* every transition is a compare and set */
UPDATE drivers SET status = 'OFFERED'
WHERE id = :d AND status = 'AVAILABLE';

Whiteboard

What you sketch in the first five minutes, before any of the detail below. Draw the map of cells, then the race that must never give one driver two rides.

1. Nearby drivers

Say: locations change every 4 seconds, so keep them in memory, in cells, and never as one database row per driver.

riverRABCDsearch the rider's celland its 8 neighborsA: 2 min by air,12 by roadB: 4 min by roadC, D: outside, skipped250,000 updates/sin memory, sharded by cityrank by arrival time on roads: B gets the offerhistory goes to a stream, never a row per update
  1. Put each driver's latest location in a cell of a grid (geohash or H3), sharded by city.
  2. For a request, take the available drivers in the rider's cell and its neighbors.
  3. Rank them by arrival time on the road graph, and offer the ride to the best one.

Next question: what if the cells hold no driver? Widen the ring of neighbors one step at a time.

2. No driver gets two rides

Say: every status change is a compare and set, so two matchers can race and only one wins.

AVAILABLEOFFEREDON_TRIPaccepttimeout 15 s or declinetrip endsmatcher 1matcher 2driver DAVAILABLESET status = 'OFFERED'WHERE status = 'AVAILABLE'1: 1 row ✓ offer2: 0 rows ✗next drivercompare and set: only one matcher can win
  1. Offer: set OFFERED only where the status is still AVAILABLE.
  2. One row changed: send the offer, with a 10 to 15 second timeout.
  3. No row changed, a timeout or a decline: move on to the next driver.

Next question: how does the rider see the car move? The driver's updates go out on a channel for the trip and reach the rider over a WebSocket.

Storing driver locations: Redis geo sets or a cell index

OptionVerdict
A database row per driver, updated every 4 s250,000 writes per second of data that is stale in seconds. The wrong tool.
Redis geo set per city (GEOADD, GEOSEARCH)In memory and simple; a solid answer for most cities.
In memory grid of cells (geohash, or H3 hexagons) sharded by cityWhat large platforms build. H3 was created at Uber for exactly this.

Location history still matters for fares, safety and analytics, so updates are also written to a stream such as Kafka and stored in bulk.

Matching riders to drivers without double assignment

Matching asks the index for available drivers in the rider’s cell and its neighbors, then ranks them by estimated time of arrival from a routing engine on the road graph, not by straight-line distance: the closest car by air may be across a river. The best candidate gets an offer with a timeout of 10 to 15 seconds; on timeout or decline, the next candidate gets it. The compare and set on driver status guarantees no driver is offered two rides at once.

Live trip tracking over a WebSocket

During a trip, the driver app keeps sending locations; the location service publishes them on a channel for that trip, and the rider’s WebSocket receives them. Updates every few seconds are enough, because the client animates smoothly between points.

What the interviewer probes next

The driver’s phone loses signal mid-trip.

The app buffers GPS points and uploads them on reconnect; the fare is computed from the full path afterwards. The rider sees the last known position with a reconnecting notice.

How does surge pricing work?

A stream job counts ride requests and available drivers per cell per minute. When demand far exceeds supply, a multiplier applies, smoothed over time so prices do not flicker.

The matching service crashes in the middle of an offer.

The ride request and its state are persisted, so another instance resumes it. Offers carry timeouts, and the driver compare and set prevents a double assignment during the handover.

How is the system partitioned?

By city or region: location index, matching and trip services all run per region, so a busy Saturday in one city cannot slow another, and an outage stays local.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy