AI Hints
Home›System Design Tutorial›Case Study: Crawling and Location
System Design · Lesson 108 of 120

Ride Matching

Drivers and riders.

⏱ 2 min read▶ Video at 2:11:19🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Now let's design the core of a ride sharing app. Drivers send their location every few seconds. Riders request a ride, and must be matched with a nearby, free driver, quickly and fairly.

Ride Matching
From the video: Ride Matching
  • Drivers send locations
  • Riders request rides
  • Match quickly

Location update load

First, estimates. Half a million drivers online, each sending a location every four seconds. Run it. That's a hundred and twenty five thousand writes per second, all the time. These locations change constantly, and old ones don't matter. So they belong in memory, in something like Redis, not in a traditional database.

rides_math.pypython
drivers_online = 500_000
every_seconds = 4

writes = drivers_online / every_seconds
print(f"location writes/sec: {writes:,.0f}")
Output
location writes/sec: 125,000

Matching a ride

Here's the matching flow. The rider requests a ride. The matching service finds free drivers in nearby geohash cells. It ranks them by distance and arrival time. It offers the ride to the best driver, who has a few seconds to accept. If they decline or time out, it goes to the next driver.

  1. Ride request
  2. Nearby free drivers
  3. Rank by ETA
  4. Offer to best
  5. Next if declined
Matching a ride
From the video: Matching a ride

Summary

Ride matching keeps driver locations in memory, finds candidates with geohashes, ranks them, and offers rides one driver at a time. Next, search autocomplete.

Key takeaways
  • ~125k location writes/sec
  • Locations in memory
  • Rank, offer, fall back
Next up: Search Autocomplete — tries and top results