Skip to main content
PreparationZone Logo
PrepZone

Proximity Service (Uber)

Match riders to nearby drivers in real time using geohash grids and streaming location updates.

Pass checkpoint below

Why this matters

  • Ride-hailing, food delivery, and StreamHub's "join nearby watch party" all need sub-second nearest-neighbour lookup over millions of moving entities.
  • Brute-force distance calculation against every driver is O(n) per request — unacceptable at Uber scale (millions of drivers online).
  • Geohash grids or quad-trees partition space so you only scan a handful of cells, not the entire fleet.

Proximity service building blocks

  • Location ingestion — drivers push GPS updates via WebSocket or UDP every 2–4 seconds.
  • Spatial index — geohash prefix tree, Redis GEO, or custom quad-tree storing driver ID + coordinates.
  • Matching engine — finds top-K nearest available drivers, applies business rules (rating, vehicle type).
  • Dispatch queue — handles concurrent match requests; first-accept-wins or broadcast-to-top-3.
  • ETA service — routing engine estimates pickup time for each candidate.

High-level architecture

Proximity / ride-matching

WebSocketCLIENT
Driver appGPS every 4s
INTEGRATION
Kinesislocation stream
DATABASE
ElastiCache G…GEORADIUS
COMPUTE
Match APIEKS
CLIENT
Rider appWS assigned
Driver GPS → Kinesis → Redis GEO → match API → WebSocket to rider.
Java
POST /v1/location/update
Authorization: Bearer <driver_token>
Content-Type: application/json

{
  "driver_id": "drv_8f2a",
  "lat": 12.9716,
  "lng": 77.5946,
  "heading": 142,
  "timestamp_ms": 1740847200000
}
Java
POST /v1/rides/request
Content-Type: application/json

{
  "rider_id": "rdr_3c91",
  "pickup": { "lat": 12.9700, "lng": 77.5900 },
  "vehicle_type": "standard"
}

Geohash grid indexing

Geohash encodes lat/lng into a base-32 string. Shared prefixes mean geographic proximity.

Java
import geohash2

lat, lng = 12.9716, 77.5946
hash_6 = geohash2.encode(lat, lng, precision=6)  # "tdr1w3" — ~1.2 km cell
hash_7 = geohash2.encode(lat, lng, precision=7)  # "tdr1w3y" — ~150 m cell

Store drivers in Redis sorted sets keyed by geohash prefix:

Java
GEOADD drivers:tdr1w3 77.5946 12.9716 drv_8f2a
GEORADIUS drivers:tdr1w3 77.5900 12.9700 2 km ASC COUNT 10

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 4 sections

  • Matching flow
  • Handling location staleness
  • Scale estimates
  • WebSocket connection management

Test yourself

Answer these before moving on — recall is what makes it stick.