Geospatial & Location ServicesGeohashingMedium⏱️ ~3 min

Trade Offs: Geohash vs H3 vs S2 in Production

Geohash Characteristics

Geohash uses rectangular cells in a Z-order curve. Cells are not equal area: they shrink toward the poles because longitude lines converge. Simple implementation with standard string operations. Works with any database that supports prefix queries.

Limitations: cell shape varies by latitude, edge discontinuities exist (neighboring cells may have very different prefixes at certain boundaries), and rectangles are poor approximations of circular query regions.

S2 Geometry

S2 projects Earth onto a cube, then subdivides each face using a Hilbert curve. Cells are roughly equal area regardless of latitude. The Hilbert curve has better locality than Z-order: nearby points more consistently have nearby cell IDs.

S2 cells have 30 precision levels. Level 12 cells are roughly 3 km by 3 km. Level 18 cells are about 38 m by 38 m. S2 supports covering arbitrary shapes with a set of cells, useful for polygon queries. More complex to implement but better geometric properties.

H3 Hexagonal Grid

H3 uses hexagonal cells. Hexagons have consistent neighbor distances: all 6 neighbors are equidistant from the center. This eliminates the corner problem where diagonal neighbors are farther than edge neighbors in square grids.

H3 has 16 resolution levels. Resolution 7 cells are about 5 km edge to edge. Resolution 9 is about 175 m. H3 excels at aggregation and visualization because hexagons tile evenly. The trade-off is that H3 IDs are not hierarchically prefixable like geohashes.

🎯 When To Use: Geohash for simple systems using standard databases. S2 for complex polygon queries and global scale with equal-area cells. H3 for hexagonal aggregation, visualization, and consistent neighbor distances. All require post-filtering for exact results.
💡 Key Takeaways
Geohash: simple, works with any database, but rectangular cells vary by latitude
S2: equal-area cells via cube projection, Hilbert curve, better for global scale
H3: hexagonal cells with equidistant neighbors, good for aggregation
Geohash is prefixable; H3 is not hierarchically prefixable
All systems need post-filtering for exact distance calculations
📌 Interview Tips
1Compare cell shapes: geohash rectangles have diagonal neighbor problem, H3 hexagons have equidistant neighbors
2For global systems, recommend S2: equal-area cells work consistently at all latitudes
3For visualization and aggregation, recommend H3: hexagons tile evenly and look better on maps
← Back to Geohashing Overview
Trade Offs: Geohash vs H3 vs S2 in Production | Geohashing - System Overflow