Uber system design: one ride request, from tap to driver
Follow one ride request through matching with Redis GEO, one-at-a-time driver offers and an atomic claim, until both phones are told.
Request a ride
- You tap request. Six drivers are moving nearby, and only one of them will get this ride.
- A load balancer picks a healthy server, and the API gateway checks who you are.
- The Ride Service creates the ride and saves it to PostgreSQL, marked searching.
- Your phone gets an answer at once, a two oh two: searching. Nothing waits for a driver.
- Meanwhile, Matching asks Redis GEO who’s nearby: six drivers, each with a location only seconds old.
- It ranks them by pickup time: Virat is two minutes away, then Chris, then Rohit.
- Dispatch offers the ride to one driver at a time, with fifteen seconds to answer. Virat gets it first.
- Virat declines, and his answer comes back on the same live socket.
- Dispatch offers Chris next. He doesn’t answer at all, so after fifteen seconds Dispatch’s timer fires, and the offer expires.
- Third in line is Rohit. The offer reaches his phone the same way, and this time, he accepts.
- Dispatch checks the offer is still live, and claims the ride in PostgreSQL: one ride, one driver.
- Only after the claim is Rohit told: head to pickup.
- The claim and a Ride Assigned event were saved together, so Kafka gets the event, and Notification tells your phone over its live socket.
- Rohit is four minutes away. Three offers, one claim, and only one driver ever gets the ride.