How would you design a 'nearby drivers' / proximity search?
822 views
70 of 106
1
The problem
Question presented to candidate:
"A rider opens our app and we want to show the drivers within a kilometre or so, and then dispatch the closest available one. Millions of drivers send their GPS position every few seconds. How do you store those positions and answer 'who is near this point' fast enough?"
What a strong answer should cover:
Why a full scan (distance to every driver) does not scale, and the idea of a spatial index: bucket the map into cells so a query looks only at nearby cells
Geohash (a prefix = a rectangle; precision picks the cell size), or H3 hexagons / a quadtree, with the trade-offs between them
The query: rider cell plus its 8 neighbours, then an exact distance filter; the cell must be at least as large as the search radius or the 3x3 block misses drivers
The write path dominates: about 1.25 million location updates per second for 5 million drivers every 4 seconds; keep positions in memory (Redis GEO or an in-process grid), with a TTL so stale drivers disappear
Sharding by geography (city or cell prefix), hot cells (airports, stadiums), and separating "nearby" from "dispatch/matching"
Capacity numbers and what breaks first at 10x
Clarifying questions expected:
How many active drivers, how often do they report, and how many ride requests per second at peak?
Search radius, and do we need the K nearest or everyone within R? Straight-line or road distance?
How fresh must positions be, and is this only for display or also for dispatch?
Code / implementation expected: Optional โ the design with numbers; the example builds a geohash index over 10,000 drivers and compares query strategies.
geo
proximity
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Developers preparing for system design interviews. You know what a database index and a cache are; no maps or geometry background needed.
Difficulty: Hard
Verified with: Node 22.22, Python 3.12, Go 1.24 and Java 21 (all four print identical output). Redis behaviour and memory were checked on Redis 7.0.15.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the exact words an interviewer expects. All behaviour shown comes from running the example; the Verified section quotes the full output. Capacity numbers are worked from stated assumptions.
1. Why This Even Matters โ A Story First
You lose your dog in a big city and call the police. A bad dispatcher reads the list of every officer in the city and asks each one "how far are you from 5th and Main?" A good dispatcher loo
The solution is hidden so you can try first
16 min read ยท 17 sections
4
Read the code
Geohash proximity search on 10,000 drivers: full scan vs own cell vs cell plus 8 neighbours, the radius trap, and cell churn