Design a ride-hailing app (like Uber)

Match riders with nearby drivers in real time, track trips and charge fares.

Why interviewers ask it

It tests geospatial search, very high-volume updates, real-time matching and preventing double-booking.

Functional requirements

Non-functional requirements

From version 1 to the final design

  1. Version 1: driver locations in a database; for each request, compute the distance to every driver.
  2. Version 2: a grid or geohash cells, searching only the nearby cells.
  3. Version 3: an in-memory geo index, a matching service and atomic driver locking.
  4. Version 4: a trip state machine, surge pricing, payments, and analytics on location history.

The design, step by step

  1. A location service takes driver updates and keeps only the latest position in an in-memory geospatial index (geohash cells, for example Redis GEO).
  2. A matching service searches nearby cells, ranks drivers by arrival time, and offers the trip to one driver at a time with a timeout.
  3. The offered driver is locked with an atomic status update, so they can't be double-booked.
  4. A trip service tracks the trip's state; pricing (including surge) and payment services handle the money.

Deep dives

Common mistakes

Not true: Every location update from every driver should be saved for ever in the main database.
In fact: Drivers report every few seconds, which would flood the database with rows that nobody reads. Keep only the latest position in memory, and stream the history to cheap storage.

In the interview

Drivers stream their location to a location service that keeps only the latest position in an in-memory geospatial index. A ride request searches nearby cells, ranks drivers by arrival time and offers the trip to one driver at a time, locking that driver atomically to prevent double-booking. Trips and payments live in a transactional database.

Part of Unit 8: High-level design questions in the free System Design course.