System Design blueprint · Mobility & Delivery
Ride-hailing driver matching
Live driver positions in a geo index, candidates ranked by road ETA, and an offer that times out.
- Steps
- 7
- Subjective questions
- 32
- Objective questions
- 32
The problem and the outcome
Problem: Riders leave if no car is found in seconds, while drivers idle a few streets away.
Outcome: Matches in seconds from live positions, with fewer empty kilometres.
Architecture
How it works, step by step
- A rider requests a ride, and the pickup point goes to the matching service.
- Every online driver's app sends its GPS position every few seconds.
- Positions live in an in-memory geo index split into cells (H3 hexagons or geohashes), so “drivers near me” is a lookup, not a scan.
- Matching reads the rider's cell and its neighbours to collect candidate drivers.
- Candidates are ranked by road ETA, not straight-line distance, and the fare is priced with current demand.
- The best driver gets an offer with a short timeout; a decline or timeout moves to the next candidate.
- An accepted ride becomes a trip with explicit states: assigned, arrived, started, completed.
Tech stack
- Uber H3 or geohash cells
- Redis GEO or in-memory geo index
- OSRM / Valhalla routing for ETA
- Kafka for location streams
- Trip state machine in a database
Key design decisions
- Bucket driver positions into hexagonal cells, so 'nearby' means this cell and its ring of neighbours.
- Rank candidates by road ETA, since the closest driver as the crow flies may be across a river.
- Offer to one driver at a time with a short timeout, so two riders never get the same driver.
Common mistakes
- Writing every GPS ping to a relational database.
- Ranking by straight-line distance only.
- Double-booking a driver when two matchers pick them at once, for want of an atomic reservation.
What to measure
- Time to match
- Driver acceptance rate
- Pickup ETA accuracy
- Share of requests with no driver found
Most-asked interview questions
Subjective questions 32
1How would you find the nearest available drivers quickly?Asked almost every time
Keep live positions in memory, indexed by geo cell (H3 or geohash), updated every few seconds. For a request, read the rider's cell and its neighbouring rings until you have enough candidates, filter by availability and vehicle type, then rank by road ETA from a routing engine.
2Walk through the architecture of a ride-hailing matching system.Asked almost every time
Drivers send location updates every few seconds to a location service that keeps the latest position in an in-memory geospatial index partitioned by city or cell. A rider request goes to a matching service that queries nearby available drivers, scores them by ETA and other factors, offers the ride to the best driver with a timeout, and on acceptance atomically marks the driver busy and creates the trip.
3How do you compute ETAs for candidate drivers?Asked almost every time
Straight-line distance is a first filter; real ETAs come from a routing engine over the road graph with live traffic (precomputed contraction hierarchies for speed). Compute ETAs only for a shortlist of nearby candidates to save cost.
4How do you handle a driver not responding to an offer?Asked almost every time
Each offer has a short timeout (around 10–15 seconds); on timeout or rejection, the matcher offers to the next best driver. Track acceptance rates, and avoid offering the same rider to many drivers at once unless using a broadcast model.
5Why hexagons (H3) rather than square geohash cells?Very often asked
Every hexagon's neighbours are the same distance from its centre, so a ring of cells approximates a circle well. Square cells have corner neighbours that are further away and edges that distort with latitude. Both work; H3 makes radius searches and surge-pricing areas more uniform.
6How do you stop two riders from being matched to the same driver?Very often asked
Reserve the driver atomically before sending an offer: a compare-and-set on the driver's state (available → offered) in Redis or the database. If it fails, move to the next candidate. The reservation expires if the driver does not answer.
7How do you store and update millions of driver locations?Very often asked
Keep only the latest location per driver in memory (Redis GEO, H3-indexed maps or a custom service), partitioned by region, with updates written to a stream for analytics. Do not write every ping to a relational database.
8How does surge pricing work?Very often asked
Compare demand (requests) with supply (available drivers) per area and time window, compute a multiplier with smoothing and caps, show it to riders before booking, and use it to attract drivers to busy areas.
9How do you match in batches instead of greedily?Very often asked
Collect requests and available drivers over a short window (a few seconds) and solve an assignment problem that minimises total pickup time across all pairs, which beats nearest-driver greedy matching in dense areas.
10How do you keep the trip state consistent?Very often asked
Model the trip as a state machine (requested, driver assigned, arriving, in progress, completed, cancelled), persist each transition in a strongly consistent store, and use conditional updates so concurrent events cannot apply invalid transitions.
11How do you scale across cities?Very often asked
Partition by city or region: each region has its own location index, matching workers and possibly database shards, since riders and drivers rarely interact across cities. A global layer handles accounts and payments.
12How do you track the driver's live location for the rider?Very often asked
Push driver location updates to the rider app over WebSockets or a streaming connection at a few-second interval, smoothing movement on the client between updates.
13What happens if the matching service fails mid-request?Very often asked
Requests are persisted with state, so another instance can resume them; driver locks have TTLs so drivers are not stuck as busy, and riders see a retry state rather than silent failure.
14How do you design scheduled rides booked hours in advance?Very often asked
Store the reservation with pickup time and location, start matching a configured window before pickup with wider search radius and incentives, notify the rider when a driver is assigned, and have a fallback that escalates priority or offers compensation if no driver accepts in time.
15How do you keep the matching service available during a sudden city-wide surge?Very often asked
Shed non-critical work such as ETA refinements for distant drivers, widen batching intervals, cap requests per area with clear 'high demand' messaging, scale the city's matcher shard, and protect the trip state store with backpressure.
16Why use H3 or geohash cells for nearby search?Often asked
Cells turn 2D proximity into key lookups: query the rider's cell and its neighbours to get candidates quickly, then refine by exact distance and ETA. H3's hexagons have uniform neighbour distances, making rings more accurate.
17How do you prevent fraud such as GPS spoofing?Often asked
Check location plausibility (speed between pings, jumps), compare with network and sensor data, detect emulators, and flag suspicious trips for review.
18How do you handle pooled rides?Often asked
Match riders whose routes overlap, insert pickups and drop-offs into an existing route if the detour stays under limits, and recompute ETAs for everyone in the vehicle.
19How do you predict demand?Often asked
Use historical trips, time of day, events, weather and holidays in forecasting models per area, and use predictions to reposition drivers and set surge in advance.
20How do you estimate load on the location service?Often asked
With 5 million active drivers sending a ping every 4 seconds, that is about 1.25 million updates per second globally, which is why updates go to in-memory, region-partitioned indexes.
21How do you make ETAs accurate?Often asked
Use live traffic data, historical speeds by time of day, map-matching of GPS traces to roads, and correct with machine learning trained on actual trip times.
22How do you handle cancellations?Often asked
Allow cancellation within rules, free the driver immediately, apply fees after a grace period, and feed cancellation patterns into matching (drivers or riders who cancel often).
23Which consistency is needed where?Often asked
Driver assignment and payments need strong consistency to avoid double booking or charges; driver locations and ETAs can be eventually consistent and slightly stale.
24How do you design driver incentives without hurting the marketplace?Often asked
Target incentives at areas and times where supply forecasts fall short, cap budgets per region, measure incremental supply with experiments rather than raw participation, and avoid incentives that pull drivers away from other busy areas.
25How do you handle a rider's pickup point being inaccessible?Often asked
Snap requested points to valid pickup spots on the road graph using map data and past successful pickups, suggest nearby better spots, allow chat or call between rider and driver through masked numbers, and update the pickup pin live.
26How do you compute and show an upfront fare?Often asked
Estimate route distance and time from the routing engine, apply the city's base, per-km and per-minute rates plus current surge and fees, lock the quote for a short time, and store it with the trip so the charged fare matches unless the route changes materially.
27How would you add safety features such as ride check and sharing a trip?Often asked
Detect anomalies like long unexpected stops or route deviations from the location stream, prompt both parties, offer one-tap emergency help, and let riders share a live trip link that shows the car and route to trusted contacts until the trip ends.
28How do you test matching changes safely?Sometimes asked
Simulate historical demand and supply with replay simulators, compare metrics like pickup time and match rate, then run regional A/B tests or switchback experiments.
29What are switchback experiments?Sometimes asked
Alternating between treatment and control over time windows within a city, because riders and drivers interact and per-user A/B tests would interfere with each other.
30Which metrics matter for ride matching?Sometimes asked
Time to match, pickup ETA, request-to-acceptance rate, cancellation rate, driver utilisation and earnings, and completion rate.
31How is privacy protected for riders and drivers?Sometimes asked
Mask phone numbers with proxy calling, share precise locations only during active trips, limit data retention and restrict internal access to trip histories.
32How do you store trip history for analytics without slowing the live system?Sometimes asked
Stream trip events through change data capture into a data lake or warehouse, keep only active trip state in the operational store, and build analytics, pricing models and dashboards from the warehouse copy.
Objective questions 32
1What best ranks candidate drivers for a pickup?Asked almost every time
Why: Road networks, one-way streets and traffic make ETA the real measure of how soon a car arrives.
2Where should the latest driver locations live?Asked almost every time
Why: Updates arrive every few seconds.
3How is double-booking a driver prevented?Asked almost every time
Why: Only one trip can claim the driver.
4What should happen when a driver ignores an offer?Asked almost every time
Why: Short offers keep riders from waiting.
5Where should driver GPS pings, sent every few seconds, be stored for matching?Very often asked
Why: Very frequent, short-lived updates fit an in-memory index; history can be streamed elsewhere.
6Why compute exact ETAs only for a shortlist?Very often asked
Why: Filter by distance first.
7Batch matching improves on greedy by…Very often asked
Why: An assignment problem.
8How should matching scale across cities?Very often asked
Why: Riders and drivers are local.
9Surge pricing compares…Very often asked
Why: Then smooths and caps a multiplier.
10Which data needs strong consistency?Very often asked
Why: Avoid double booking and charges.
11How does the rider see the car moving?Very often asked
Why: Updates stream over WebSockets.
12Matching for a scheduled ride starts…Very often asked
Why: Drivers near the time and place are the useful candidates.
13During a demand surge the matcher should first shed…Very often asked
Why: Core matching and trip consistency must keep working.
14What does a geohash or H3 cell ID represent?Often asked
Why: Both encode an area on the map, so nearby points share a cell or a prefix.
15Why do H3 hexagons help nearby search?Often asked
Why: Rings of neighbours are accurate.
16GPS spoofing is detected by…Often asked
Why: Check location plausibility.
17About how many updates per second do 5M drivers pinging every 4 s send?Often asked
Why: 5 million divided by 4.
18Pooled rides insert a new rider when…Often asked
Why: Recompute ETAs for all.
19Which experiment design suits marketplaces?Often asked
Why: Riders and drivers interfere.
20What should happen to a driver lock if the matcher crashes?Often asked
Why: Drivers must not stay stuck.
21Trip states should be stored…Often asked
Why: Invalid transitions are rejected.
22What improves ETA accuracy?Often asked
Why: Map-matching helps too.
23Driver incentives should be judged by…Often asked
Why: Paying drivers who would have driven anyway adds nothing.
24Pickup pins are snapped to…Often asked
Why: Drivers need a reachable spot on the road.
25An upfront fare quote should be…Often asked
Why: The charge should match what the rider accepted.
26Route deviation alerts come from…Often asked
Why: Real-time location reveals unexpected stops or detours.
27How are phone numbers protected?Sometimes asked
Why: Privacy for both sides.
28Demand forecasting helps…Sometimes asked
Why: Supply meets predicted demand.
29Which metric shows matching quality for riders?Sometimes asked
Why: Riders feel these directly.
30Driver pings should also go to…Sometimes asked
Why: Keep the hot path in memory.
31Cancellation after a grace period may…Sometimes asked
Why: Discourages late cancellations.
32Historical trip analytics should run on…Sometimes asked
Why: Analytics should not load operational systems.
Track your progress through every blueprint in your dashboard.
Start learning