Home/Labs/Ride Dispatch Geo Rings
All 280 Labs
INTERACTIVE LAB🚕

Ride Dispatch Geo Rings Lab (Interactive)

Expand H3 hex rings around a rider and count candidates vs geohash and SQL latency. Compare H3 hexagonal rings, geohash cells, and SQL bounding-box scans for matching nearby drivers to a dispatch request.

Uber Dispatch: H3 Rings vs Geohash Buckets vs SQL Scan

1M drivers report GPS every 4 seconds (250k writes/s). Expand search rings and count what each spatial index actually touches.

6 drivers matched within 2.5 km (top 6 by ETA)Rider cell 8831cea…res8
Driver P (Camry)
cell 88310100a
0.4 kmroad ETA ~4 min (OSRM/routing engine)
Driver [ (Civic)
cell 88310100a
0.4 kmroad ETA ~3 min (OSRM/routing engine)
Driver p (Camry)
cell 88310103a
1 kmroad ETA ~6 min (OSRM/routing engine)
Driver V (Corolla)
cell 88310105a
1.2 kmroad ETA ~5 min (OSRM/routing engine)
Driver a (Prius)
cell 88310106a
1.2 kmroad ETA ~7 min (OSRM/routing engine)
Driver d (Ioniq 5)
cell 88310107a
1.4 kmroad ETA ~6 min (OSRM/routing engine)
Cells scanned373 hex rings (6r/circle)
Candidate drivers6,845of 1,000,000 registered
Query latency1.7 ms
Ingestion load250k w/s1M drivers ÷ 4s GPS tick, 128 MB Redis
Why H3 won at Uber

› Hexagons: all 6 neighbors equidistant (squares give diagonal √2 ≈ 1.414× distortion), and each cell ≈ 0.74 km² at res 8.

› A cell is just a 64-bit integer → SMEMBERS h3:8831cea… is one Redis hash-tag sharded lookup; driver registry mutates only when a driver crosses a cell border.

› Geohash boxes distort: the rider's true neighbors are not prefix-adjacent, so 8 neighbor prefixes must be enumerated — and corner cells leak candidates.

› Euclidean SQL over lat/lng scans all 1M rows per dispatch, and straight-line distance mis-ranks drivers behind one river or freeway.

How It Works Under the Hood

Ride dispatch must find every driver within R km many times per second, and the spatial index choice sets both candidate volume and latency. H3 tessellates the globe into hexagons, where resolution 8 cells cover about 0.74 km^2, whose ring expansion of r rings covers exactly 1 + 3r(r+1) cells — near-circular and free of the corner gaps that plague square and geohash cells. You expand a ring sized to the radius, query drivers bucketed into those cells, then run a precise haversine filter on the small candidate set. Toggle H3, geohash, and a naive SQL bbox to watch candidate counts and per-query latency swing across the seeded driver fleet.

Core Architectural Principles

  • An H3 ring of radius r covers 1 + 3r(r+1) cells; resolution-8 cells are about 0.74 km^2.
  • The coarse cell query returns candidates, then exact haversine prunes to the true radius.
  • SQL bounding-box scans every row in the box as an indexed range — far more candidates than H3 rings.
Interview Round Script

Explain why you cannot use a plain distance predicate over millions of drivers, then present a spatial index — geohash prefix, H3 hexes, or a quadtree — and the two-phase candidates-then-refine pattern. H3's equal-area hexes and clean ring expansion beat geohash's rectangular cells for radius queries. Discuss bucketing drivers by cell in memory, matching-ring growth over time, and in-process driver-location updates.

Key Trade-Offs

H3 gives uniform hexagonal rings with no corner artifacts but adds index complexity; geohash is simpler to store yet over-scans at box edges.

Related Curriculum Chapter

Design a Ride-Sharing Dispatch System (Uber / Lyft)

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs