KatInterview

Backend Design for a City-Scale Taxi Dispatch Service

System DesignModel answer
HardModel answerSystem Designsystem-designgeospatial-indexingreal-time-streaming

Last updated

Design the backend for a multi-city on-demand taxi app: dispatch, live driver tracking, dynamic pricing, durable payments and trip records, and resilience at millions of daily users.

Problem

Design the backend for an on-demand taxi platform that operates in many cities and serves millions of daily users. Passengers book a car from a pickup point to a drop-off point, and nearby drivers are matched to them automatically.

What the product must do

Passengers can:

  • Register, sign in, and edit their profile.
  • Ask for a trip by giving a pickup and a destination.
  • See nearby available cars with an estimated arrival time.
  • See a fare estimate before they confirm.
  • Watch the assigned car move on a map in real time.
  • Pay with a saved payment method such as a card.
  • Rate the driver afterwards.

Drivers can:

  • Register, complete onboarding, and add their vehicle.
  • Switch between online and offline.
  • Receive trip offers and accept or decline them.
  • Navigate first to the passenger and then to the destination.

The platform must:

  • Match passengers with suitable nearby drivers automatically.
  • Raise prices in areas where demand exceeds supply (dynamic pricing).
  • Keep a history of trips (route, price, timestamps) for both sides.
  • Send push or SMS notifications as the trip status changes.

Quality requirements

  • Availability: the service keeps working when individual components fail.
  • Latency: arrival estimates and match results appear within a few hundred milliseconds; vehicle positions look close to live.
  • Scale: millions of daily active users across several regions.
  • Correctness: payments and trip records are never lost and never charged twice. Live location may be eventually consistent.
  • Security and privacy: user data and payment details are protected.

What to cover in your answer

  1. Overall architecture: the main services and how they communicate.
  2. Data model and storage: key entities, a rough schema, and which database type holds what.
  3. The booking and matching flow, including how to find and pick a nearby driver efficiently.
  4. Real-time location: how drivers report positions and how the system stores and serves them for ETAs and maps.
  5. Scaling and partitioning: sharding strategy and how to handle rush-hour hotspots.
  6. Reliability: handling service and data-center failures, and keeping payments and trip data durable.
  7. Briefly: dynamic pricing, plus monitoring, logging, and the metrics you would track.

State your scale assumptions and do a quick back-of-the-envelope estimate first.

Hints

Hint 1

Estimate the load before drawing boxes. Frequent driver location pings produce far more writes than trip requests, so the two paths need different storage and consistency models.

Hint 2

Use a spatial grid (geohash, H3, or S2) to look up nearby drivers, then rank candidates by road-network ETA rather than straight-line distance. Reserve a driver atomically so nobody receives two offers at once.

Hint 3

Model the trip as a state machine with conditional writes, and make payment calls idempotent with unique keys. That makes retries, duplicate events, and out-of-order messages harmless.

Hint 4

Partition by city or region first, then split hot cities by grid cell. Treat live location as soft state with a TTL so it rebuilds itself after a node failure.