The "Near Me" Interview: Designing a Proximity Service
It's 12:10 on a Tuesday. Someone standing in a Manhattan park types "ramen", taps search, and in about a tenth of a second sees twenty places, ranked, on a list and on a map. Behind that tap sits one of the most popular questions in the Staff/Principal interview loop. It's popular because it looks like a database query and is actually four hard problems stacked together: indexing two-dimensional space, ranking by more than distance, keeping 200 million places fresh, and doing it all worldwide without leaking where people are.
Why Interviewers Love This Question
The proximity prompt is easy to start and hard to finish well. Most candidates can say "geohash". Far fewer can say what happens next, and the interview is built to find out. Three traps sit just under the surface:
- The Scan-and-Sort Trap: The candidate filters by a latitude range and a longitude range, then sorts by distance. On a corpus of 200 million points, a two-column B-tree turns a 2D question into a stripe scan, and distance alone ranks a 3-review newcomer above the neighborhood institution. Signal: no feel for spatial indexing or relevance.
- The Three-by-Three Trap: The candidate knows geohashes and queries the center cell plus its eight neighbors. A precision-6 cell is only about 0.61 km tall at any latitude, so a 1 km circle spills out of that block. Signal: the vocabulary is there, the geometry isn't.
- The Fan-Out Trap: The candidate hash-shards the index by place id and calls the reviews service for every result. Every search now touches 64 shards and makes 20 extra calls, and the p99 belongs to the slowest of them. Signal: the design was never followed from one request to its end.
The passing performance turns each trap into a design decision. Compute a covering of geohash cells from the radius's bounding box, then filter by exact distance. Shard the index by geography, so a local query touches one shard (two at a range boundary). Denormalize review aggregates into the index. Rank in two stages over a bounded candidate budget. Cache by cell, not coordinate, so the cache actually hits and raw locations never land on disk.
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson