Skip to content
All problems

Design a ride-hailing dispatch system

breadth · 45 min · senior/staff

Setting

You're on the marketplace team at a ride-hailing app: riders request a trip, nearby drivers are shown or matched, and both sides need to see each other's live location for the duration of the trip.

The ask

Design the system that matches a rider's request to a nearby available driver and keeps both apps updated with live location until pickup.

Constraints & scale

  • ~5M concurrent drivers reporting location during peak hours, location updates every 3–5 s per active driver
  • Match latency: a rider should see a matched driver within a few seconds of requesting
  • A driver can only be matched to one rider at a time; two dispatch attempts must never double-book the same driver
  • Surge periods (a big event ending) spike both demand and the number of "nearby" candidates the matcher has to consider in a small radius
  • Driver and rider apps need live location updates during the match wait and the ride itself, not just at request time

What a strong answer covers

Requirements → estimates (location update volume, geo-index size) → data model / geo-indexing approach → high-level diagram (location ingestion, matching, live tracking) → 1–2 deep dives → trade-offs. Likely probes: how you index and query "nearby available drivers" at this scale, the double-booking race, and how live location reaches both apps efficiently.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Estimates (location update volume, geo-index size)
  3. Data model / geo-indexing approach
  4. High-level diagram (location ingestion, matching, live tracking)
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • How you index and query "nearby available drivers" at this scale
  • The double-booking race
  • How live location reaches both apps efficiently

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Spatial index choice. Geohash cells are simple, work with ordinary key-value stores and have uneven density, with awkward neighbours at cell edges. A quadtree adapts to dense areas and is harder to shard and update. Fixed-size cells are easy to reason about, and a busy city centre will overload one.
  • Cell size. Small cells make each lookup cheap and need more cells to search and more updates when a driver crosses a boundary. Large cells reduce crossings and return more candidates to filter. Density should drive it, so you may need different sizes for city and countryside.
  • Match quality or speed. Taking the nearest available driver immediately is fast and can be a poor global choice. Batching requests for a few seconds and solving the assignment together improves overall wait time and delays every rider slightly. Surge is where batching pays off most.
  • Location update handling. Writing every ping to durable storage is expensive at millions of drivers and a few seconds apart. Keeping the live position in memory and sampling to durable storage for history is far cheaper. Define what you lose if the memory store restarts.
  • Locking a driver. Claiming a driver with a conditional update prevents double-booking and needs a timeout so a driver who never answers is released. Short timeouts keep the pool moving and lose some willing drivers. Offering a request to several drivers at once speeds matching and wastes some drivers' attention.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • Scanning all drivers for each request. Distance against a whole city of drivers does not fit a few-second budget.
  • Check-then-assign. Two matchers can see the same driver as free and both book them. The claim must be one atomic step.
  • Querying a single cell. The nearest driver is often just over an edge, so search neighbouring cells and sort by real distance.
  • Using straight-line distance only. A driver across a river or on the other side of a one-way system can be many minutes away. Use an estimated travel time at least for the final ranking.
  • No handling of a driver who declines or disappears. Without timeouts and reassignment, riders wait on a match that will never arrive.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.