Design Uber: location, matching, and trip service
Uber
Guided ModeStep 4 β Geo Index (Redis Geo)
Request Flow
GEOADD on ping
Location Service calls GEOADD fleet:NYC <lng> <lat> driver_id. Redis converts coordinates to a geohash integer score and stores driver_id in a sorted set. Cost: ~1 Β΅s per write. Capacity: 200K writes/second per instance.
GEORADIUS query
Matching Service will call GEORADIUS fleet:NYC <lng> <lat> 3 km ASC COUNT 20 on the Cache. Redis checks the center geohash cell + 8 surrounding cells β returns 20 nearest drivers in <2ms, even with 1M drivers in memory.
Why not PostGIS?
PostGIS with a GIST index handles ~10-20K location updates/second. Redis Geo handles 200K+/second. For radius queries, PostGIS takes ~10ms; Redis takes <2ms. 100x improvement in both write throughput and query latency.
Why We Need This
Geohash converts 2D space into a 1D sorted key. Nearby points share geohash prefixes. A radius search becomes: find all points in the 9 geohash cells surrounding the query point β O(9 sorted-set range scans) instead of O(n) distance computations.
Key Insight
Geohash turns nearest-neighbour search from O(n) to O(1). A 3 km radius at precision-6 covers 9 cells of ~1.2 kmΒ² each β checking ~20-50 drivers instead of 100,000.
Step 4 of 8
