SDE & MLE Prep

Geospatial Indexing

"What's near me?" — map 2-D points to something an ordinary index can search.

IndexIdeaNotes
Geohashinterleave latitude/longitude bits → base-32 string; shared prefix ≈ nearby5 chars ≈ 4.9 × 4.9 km, 6 ≈ 1.2 × 0.6 km, 7 ≈ 153 × 153 m; query the cell + its 8 neighbours (edge effects); works in any B-tree/KV store and Redis GEOSEARCH
Quadtreesplit a cell into 4 once it holds more than K pointsadapts to density (cities vs oceans); usually an in-memory structure
S2 / H3hierarchical cells on the sphere (S2: Hilbert curve on a cube; H3: hexagons)region coverings; H3's equidistant neighbours suit ride-hailing and surge pricing
R-tree (PostGIS GiST)nested bounding rectanglespolygons and "within shape" queries

Rules of thumb: static places (Yelp) → precompute an in-memory index and replicate it; moving objects (drivers, friends) → keep only the latest position in memory (Redis GEO, sharded by region) and stream the history elsewhere.