Explore / Backend system design

Design a Ride-Hailing App (Uber)

Overview

Design the core of a ride-hailing app like Uber, Lyft or Ola. A rider opens the app, sees nearby cars and a price, requests a ride, and is matched with a driver who accepts. Both watch each other move on the map until pickup, then the trip runs to the destination and is charged.

Two things make this question hard. Drivers move all the time: millions of phones send their position every few seconds, and "who is near this point right now?" must be answered in milliseconds over data that is never still. And matching is a concurrency problem: two riders must never be given the same driver, a driver who ignores an offer must not block the rider, and all of it must work when a phone loses signal under a bridge. Write your answer in the Write tab and sketch the architecture in the Diagram tab.

Requirements

Functional

  • Riders see nearby available drivers and an upfront price for a trip.
  • Riders request a ride; the system offers it to a suitable driver, who accepts or declines.
  • Riders and drivers see each other's live location until pickup, and the trip's route afterwards.
  • Trip lifecycle: requested, matched, driver arrived, in progress, completed, cancelled.
  • Prices rise where demand exceeds supply (surge).

Non-functional

  • Fast matching: a driver is found and offered the trip within a few seconds.
  • Fresh locations: positions on the map are at most a few seconds old.
  • No double assignment: a driver is never on two trips or two pending offers.
  • Highly available in every city; a failure in one region doesn't stop another.
  • Scale: millions of drivers online at peak and tens of millions of trips a day.

Estimates

Assume 5 million drivers online at peak, each sending a location every 4 seconds, about 20 million trips a day with a 3× peak, and 10 price quotes for every completed trip (people check prices without booking). A location update is about 100 bytes. Work out:

  • Location updates per second at peak, and their bandwidth.
  • Trips and price quotes per second.
  • Memory needed to hold every online driver's latest position.
  • Storage per day if you keep every location point.

Hints

  • A database query "drivers within 2 km of this point" on rows that change every 4 seconds: what does it cost?
  • How can you turn a position on a map into a key you can look up quickly?
  • Is the nearest driver by straight-line distance the best driver? Think about a river between them.
  • Two riders' requests reach two servers at the same moment and both pick driver D. What stops a double assignment?
  • A driver gets an offer and doesn't respond. How long does the rider wait?

Follow-ups

  • How would you match riders going the same way into one shared ride?
  • How do you handle a city where the data centre serving it goes down mid-trip?
  • How would you detect and handle a driver faking their GPS location?
  • How do you scale for New Year's Eve at midnight in one city?
  • How would you estimate arrival times accurately?

Write your answer step by step and compare it with the reference solution on GrindPrep.