Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Ride-Hailing Geospatial Matching
& Dispatch Engine (Uber Scale).

Architect an Uber-scale geospatial matching and dispatch platform ingesting 1M+ driver GPS pings/sec, computing real-time surge/ETA, and locking drivers atomically without double-dispatch.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

If latency budgets leave no room for synchronous retries, stream GPS pings via Kafka/Flink into a city-partitioned in-memory H3 index, rank k-ring candidates by road ETA, and use a Stateful Trip Offer Manager with distributed driver leases to prevent double-booking.

TL;DR30-second simplified summary
▾

1M+ GPS pings/sec partition by city_id through Kafka and Flink into RAM-resident H3 indexes. Dispatch batches requests over 2-second windows for bipartite ETA matching and acquires 15s Redis NX leases before pushing offers.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Geospatial Indexing: Uber H3 Hexagons, Geohash & Quadtrees
Geospatial indexing maps 2D (lat, lon) coordinates into 1D cell IDs for fast proximity lookups; Uber H3 uses hexagonal cells so every neighbor is equidistant, eliminating square-grid corner distortion.
Full walkthrough · 7 stages
01
foundation

High-Throughput Driver GPS Ingestion (1M+ Pings/Sec).

Why this matters: Ingest and map-match millions of noisy mobile GPS pings per second without choking databases.

4 million drivers pinging every 4 seconds generate 1M QPS.

Mobile apps batch/compress telemetry over persistent gRPC/WebSocket gateways into Kafka partitioned by city_id.

FOUNDATION

Kafka + Flink GPS Ingestion

Driver AppsingressKafka (city_id)streamFlink Map-MatchercomputeStorecomputes Res 9 H3 cell

1.Metro Partitioning: Keying Kafka by `city_id` keeps regional spatial indexes local.

2.Kalman Snapping: Map-matching prevents urban canyon GPS drift from misplacing drivers.

Partitioning GPS streams by `city_id` feeds regional in-memory H3 indexes at 1M+ QPS.

02
foundation

Metro-Region Partitioning & Stateless vs. Stateful Separation.

Why this matters: Scale the in-memory spatial index horizontally by city/metro boundary with zero cross-region queries.

Think of Metro-Region Partitioning & Stateless vs. Stateful Separation as the intuition layer for Design a Ride-Hailing Geospatial Matching & Dispatch Engine (Uber Scale): Scale the in-memory spatial index horizontally by city/metro boundary with zero cross-region queries.

A rider in Bengaluru never needs to match a driver in London. Partitioning the In-Memory H3 Index and Dispatch clusters by metro region (city_id) keeps each cluster's working set small enough to fit completely in RAM (e.g., 100k drivers = <50 MB) with active-passive failover per city.

FOUNDATION

City-Isolated Spatial Clusters

API GatewayingressBengaluru ShardcomputeNYC ShardcomputeStoreroutes NYC rides

1.Blast Radius: A traffic spike or outage in one city never affects other metros.

2.Sub-Millisecond RAM: Keeping a city's active drivers in RAM avoids disk/network hops.

Metro-region sharding isolates failure domains and keeps every city's H3 index in RAM.

Engineering Decision Framework
Problem
How to implement Design a Ride-Hailing Geospatial Matching & Dispatch Engine (Uber Scale) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
If latency budgets leave no room for synchronous retries, stream GPS pings via Kafka/Flink into a city-partitioned in-memory H3 index, rank k-ring candidates by road ETA, and use a Stateful Trip Offer Manager with distributed driver leases to prevent double-booking.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Ride-Hailing Geospatial Matching & Dispatch Engine (Uber Scale) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Greedy Nearest-Driver vs. Batched Bipartite Matching.

Why this matters: Maximize global fleet efficiency by batching nearby requests over 2-second windows.

Think of Greedy Nearest-Driver vs. Batched Bipartite Matching as the intuition layer for Design a Ride-Hailing Geospatial Matching & Dispatch Engine (Uber Scale): Maximize global fleet efficiency by batching nearby requests over 2-second windows.

Naive greedy matching (immediately assigning the closest car to Rider A) can cause Rider B 100 meters away to wait 10 minutes for a distant car. Accumulating requests in a 2-second window per zone and solving minimum-weight bipartite matching (Hungarian / min-cost flow) reduces average global ETA by 10-15%.

INTERMEDIATE

2s Batched Bipartite Dispatch

2s Batch WindowingressBipartite SolvercomputeOptimal PairingsoutputStoreemits globally optimal matches

1.2-Second Trade-Off: A 2s matching delay is invisible to riders and cuts deadhead miles.

2.Dynamic Falloff: Low-density suburbs fall back to immediate greedy dispatch.

Short 2-second batching windows optimize global pickup ETAs across competing riders.

04
intermediate

Preventing Double-Dispatch with Distributed Driver Leases.

Why this matters: Guarantee a driver receives at most one active trip offer at a time using atomic Redis leases.

When two Dispatch workers simultaneously pick the same driver for two riders, sending both offers causes double-booking and cancellations.

Before pushing an offer, the Stateful Trip Offer Manager acquires an exclusive 15-second Redis lease (SET lock:driver:{id} {trip_id} NX EX 15).

INTERMEDIATE

Exclusive Driver Offer Lease

Matched DriveringressRedis NX EX 15sgatePush Trip OfferoutputStorepushes offer only to winner

1.Safe Unlock: Always check `value == trip_id` in Lua before deleting a lease on decline.

2.Auto-Expiry: 15s TTL automatically frees the driver if their phone loses signal.

Atomic Redis leases with owner-checked Lua release prevent double-dispatch races.

05
intermediate

Stateful Trip Offer & Timeout Re-Matching Loop.

Why this matters: Handle driver declines, network drops, and acceptances cleanly with an event-driven state machine.

Once an offer is pushed, a 15-second timer starts.

If the driver accepts (ACCEPTED), the trip transitions to DRIVER_EN_ROUTE and persists to CockroachDB/PostgreSQL.

INTERMEDIATE

Trip Offer State Transitions

OFFER_PENDINGstateDRIVER_EN_ROUTEoutputDECLINED / EXPIREDcomputeStoredecline or 15s timeout

1.Decline Exclusion: Excluding declined drivers prevents re-offering the same trip.

2.Idempotent Accept: Late accepts after 15s expiry return HTTP 409 Offer Expired.

An explicit offer state machine with exclusion lists recovers smoothly from driver declines.

06
advanced

Real-Time Supply/Demand Surge Pricing on Res 7 Hexagons.

Why this matters: Compute smooth, tamper-resistant surge multipliers using 1-minute rolling H3 windows.

If a concert ends, 500 riders open the app in one Res 7 hexagon.

A Flink window aggregates open_ride_requests vs.

ADVANCED

Spatially Smoothed Surge Engine

Rider App OpensingressAvailable Driversingressk=1 SpatialSmoothingoutputStoreblends with 6 H3 neighbors

1.Neighbor Smoothing: Blending with 6 H3 neighbors prevents sharp price cliffs across blocks.

2.Quote Lock: Caching `quote_id` for 5 minutes guarantees price consistency at booking.

Spatially smoothed Res 7 surge ratios prevent sharp price cliffs while balancing local supply.

07
advanced

Active Trip Tracking, Partitioned Ledger & Live Rider Map.

Why this matters: Stream matched driver GPS updates directly to the rider's map while keeping trip state durable.

Think of Active Trip Tracking, Partitioned Ledger & Live Rider Map as the intuition layer for Design a Ride-Hailing Geospatial Matching & Dispatch Engine (Uber Scale): Stream matched driver GPS updates directly to the rider's map while keeping trip state durable.

Once DRIVER_EN_ROUTE, the driver's 4-second GPS pings still flow through the ingestion pipeline, but Flink routes pings for active trip_ids to a dedicated trip.tracking WebSocket/PubSub channel pushed to the rider's map. Trip state transitions (REQUESTED -> MATCHED -> IN_PROGRESS -> COMPLETED) write to a geo-replicated SQL ledger.

ADVANCED

Live Trip Tracking & SQL Ledger

Matched Driver PingingressTrip Pub/Sub -> WSoutputGeo-Replicated SQLstorageStorelogs route polyline & transitions

1.Dual Path: Ephemeral car animations use Pub/Sub; billing/state transitions use ACID SQL.

2.Offline Resilience: Driver app buffers GPS waypoints locally during tunnels and syncs at drop-off.

Splitting ephemeral live map streaming from ACID trip ledgers keeps both fast and auditable.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How does the Trip Offer Manager prevent two concurrent riders from being matched to the exact same driver?

Recommended Learning Flow