Skip to content
Preptima
hardDesignConceptMidSeniorStaff

You need every driver within two kilometres of a moving rider, updated every four seconds. What index makes that cheap?

A geospatial index for nearby drivers reduces latitude and longitude to ordered cells such as geohash, S2 or H3. Query the rider's cell plus neighbours, keep the hot current-position index in memory because positions churn, and filter candidates by true distance afterwards.

6 min readUpdated 2026-08-15

Answer

Short answer

Use a geospatial cell index such as geohash, S2 or H3 for nearby-driver search. Store each driver's current cell in an in-memory index, query the rider's cell plus neighbouring cells to avoid boundary misses, then run a real distance calculation on the candidate set. The index narrows the search cheaply; it is not the final distance answer.

Was this answer helpful?

Likely follow-ups

  • Cell size is fixed at design time but driver density varies by a factor of a thousand between a city centre and a motorway. What do you do?
  • Where do you keep the driver's location history for billing disputes, and why is it a different store from the one serving searches?
  • The rider asks for drivers within two kilometres but you want them ranked by driving time. What extra system does that need, and how many candidates do you send it?
  • How would you answer the reverse query, "which riders are inside this driver's ten-minute reach", without inverting the whole index?

Related questions

Related Topics