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.
› 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.
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.
H3 gives uniform hexagonal rings with no corner artifacts but adds index complexity; geohash is simpler to store yet over-scans at box edges.