NewThe Learning module is now liveSee what's new
Advanced
Geospatial Indexing
30 min readChapter 15Optional

1. Geospatial indexing

Open a food-delivery app and it shows you restaurants within 3km. The obvious backend is a restaurants table with lat and lng columns and an index on both. That works on a laptop and falls over in a real city, because a normal index sorts by one column at a time and "within 3km" is a question about two.

A geospatial index fixes this. It maps each coordinate onto a cell, a small named patch of the map, so a radius search becomes a handful of cell lookups plus an exact distance check.

In interviews this comes up in every "nearby" prompt: Yelp, Uber, food delivery, Find My Friends. The interviewer asks how you find restaurants within 3km, then pushes on the edges of cells, dense downtowns, and thousands of location updates per second. Outside those prompts it rarely appears, so treat it as a focused deep dive worth 5 to 10 minutes, not a topic to raise on your own.

A mid-level answer needs cells, neighbor lookups, and the distance filter. A senior answer also picks an index for the city's density, separates things that stay put from things that move, and has a plan for hot cells. We'll use one food-delivery app throughout: 200k restaurants in a metro area around 40° N, and 40k active couriers who each report their location every 4s.

premium content mask
Upgrade to premium and unlock full chapter
Spot an issue or have a suggestion?

Discussion

Upgrade to premium to read and join the discussion.