# Design Ride Matching (Uber, Ola, Rapido)

> Track millions of moving drivers, find nearby ones with geospatial indexing, match riders reliably and manage the trip lifecycle. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/system-design/case-ride-matching
Last updated: 2026-11-28

Track millions of moving drivers, find nearby ones with geospatial indexing, match riders reliably and manage the trip lifecycle.

Advanced · about 5 hours · difficulty 4/5

Learn first: [Redis in Practice](https://www.internhack.in/roadmaps/tracks/system-design/redis-in-practice), [Event Streaming with Kafka](https://www.internhack.in/roadmaps/tracks/system-design/kafka-event-streaming), [Sharding and Partitioning](https://www.internhack.in/roadmaps/tracks/system-design/sharding-partitioning)

Ride hailing combines high-frequency location writes, geospatial queries and a matching process that must never assign one driver to two riders.

### Requirements

- Drivers send location every few seconds; riders see nearby cabs.
- A rider requests a ride; the system finds and offers it to suitable nearby drivers; one accepts.
- Trip lifecycle: requested, driver assigned, arriving, in progress, completed, paid; plus cancellations.
- ETA and pricing (including surge), live tracking for the rider.

### Location ingestion

With 10 lakh active drivers sending updates every 4 seconds, that is about 2.5 lakh writes per second. Keep **current location in memory** (Redis or an in-memory location service), not a disk database; stream updates through Kafka for history, analytics and ETA models.

### Geospatial indexing

You need "drivers within 2 km of this point" fast:

- **Geohash**: encode lat/long into a string; nearby points share prefixes. Query the cell and its 8 neighbours.
- **Quadtree**: recursively split dense areas; good for uneven density (Bengaluru vs rural areas).
- **H3** (Uber's hexagonal grid) or **S2** (Google): cells with uniform neighbours, used widely in production.

Redis GEO commands work well for a prototype. Shard the location index by **city or region**, since matching is local.

### Matching

1. Find candidate drivers in nearby cells, filter by vehicle type and availability, rank by ETA (road distance, not straight line).
2. Offer to the best driver with a short timeout; if declined or timed out, offer to the next (or offer to a few in parallel).
3. Make assignment **atomic**: a driver's status changes from AVAILABLE to ASSIGNED with a conditional update so two riders cannot get the same driver.

A **trip service** owns the trip state machine; a **dispatch service** runs matching per city.

### Other concerns

Surge pricing from demand/supply ratios per cell, live tracking pushed over WebSockets, payments after the trip, and handling flaky driver connectivity.

### Pitfalls

- Writing every location ping to a relational database.
- Straight-line distance for ETA in cities with rivers and one-way roads.
- Race conditions that double-assign drivers.

You are ready to move on when you can explain how a rider's request finds the nearest available driver in under a second and why a geospatial index is needed.

## Key concepts

- **High-frequency location ingestion**
- **Geohash**
- **Quadtree**
- **H3 and S2 cells**
- **Driver offer and timeout flow**
- **Atomic driver assignment**
- **Trip state machine**
- **Surge pricing**

## Mini project

Simulate 10,000 drivers moving around a city map and sending locations to Redis GEO every few seconds. Build a request endpoint that finds the 5 nearest available drivers, offers sequentially with timeouts, and assigns atomically. Report p99 matching time.

## Check yourself

Why is a geohash or H3 cell lookup much faster than computing the distance from the rider to every driver, and what edge case do neighbouring cells solve?

## Free resources

- [H3 hexagonal grid system](https://h3geo.org/) (Uber)
- [Uber engineering blog](https://www.uber.com/blog/engineering/) (Uber)
- [Geohash](https://en.wikipedia.org/wiki/Geohash) (Wikipedia)
- [Redis documentation (geospatial)](https://redis.io/docs/latest/) (Redis)

Previous: [Design a Video Streaming Platform (YouTube, Hotstar)](https://www.internhack.in/roadmaps/tracks/system-design/case-video-streaming) · Next: [Design a Payment System (UPI-style)](https://www.internhack.in/roadmaps/tracks/system-design/case-payments-upi)

## More in HLD Case Studies: Large Products

- [Design a Chat App (WhatsApp)](https://www.internhack.in/roadmaps/tracks/system-design/case-chat-app)
- [Design a News Feed (Instagram, Twitter, LinkedIn)](https://www.internhack.in/roadmaps/tracks/system-design/case-news-feed)
- [Design a Video Streaming Platform (YouTube, Hotstar)](https://www.internhack.in/roadmaps/tracks/system-design/case-video-streaming)
- [Design Ride Matching (Uber, Ola, Rapido)](https://www.internhack.in/roadmaps/tracks/system-design/case-ride-matching)
- [Design a Payment System (UPI-style)](https://www.internhack.in/roadmaps/tracks/system-design/case-payments-upi)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [System Design Roadmap](https://www.internhack.in/roadmaps/tracks/system-design)
