A hexagonal spatial indexing system using Uber's H3 library to deliver 2-10x faster geolocation queries for nearby establishment searches.
Clube Certo's platform needed to show users nearby partner establishments based on their location. The existing approach calculated Haversine distances against every establishment address in the database for every query — a brute-force method that scaled poorly as the establishment network grew.
With thousands of establishment addresses and high query volume, search latency was becoming a bottleneck. The system needed a spatial indexing strategy that could pre-filter candidates before running expensive distance calculations.
I implemented Uber's H3 hexagonal hierarchical spatial index to partition the globe into hexagonal grid cells. Each establishment address is pre-indexed into cells at three resolutions, and user queries expand outward from the user's cell using k-ring traversal — only calculating actual distances for the small subset of addresses in nearby hexagons.
H3's core library is written in C, and the existing Node.js bindings didn't cover all the functionality I needed. I translated key portions of the C implementation into JavaScript/TypeScript, adapting the low-level coordinate and indexing logic to work natively in our Node.js backend without native compilation dependencies.
Each address is indexed at three H3 resolutions to balance precision and query performance at different zoom levels:
| Resolution | Cell Edge Length | Use Case | DB Column |
|---|---|---|---|
| Resolution 7 | ~1.22 km | Default map view, city-wide search | h3_cell_res7 |
| Resolution 8 | ~461 m | Neighborhood-level zoom | h3_cell_res8 |
| Resolution 9 | ~174 m | Street-level precision | h3_cell_res9 |
Want to see more of my work?
All Projects