How Your Food Gets
Assigned a Driver in ~200ms

Real system design — Redis Geo, Distributed Locks & WebSockets. Not a toy app.

5km
Search Radius
<200ms
Total Latency
30s
Driver Timeout
// Section 02

Interactive Geo Visualization

Redis GEORADIUS query — searching for available drivers within 5km of the restaurant.

Strategy:
Restaurant drivers:geo:blr Bengaluru, India
Available driver
Busy driver
Restaurant
Selected driver
Click "Run GEORADIUS" to query driver positions...
// Section 03

Assignment Flow Timeline

Step-by-step breakdown of the full assignment pipeline — from POST request to delivery confirmation.

// Section 04

Race Condition Simulator

See why distributed locks matter — two concurrent orders targeting the same available driver.

Without Lock UNSAFE
💥 Double Assignment! Driver assigned twice.
With Redis Lock SAFE
✓ One order wins. Other retries next driver.
// Section 05

Redis Command Console

Every command our system runs — hover to see what it does in plain English.

redis-cli · drivers:geo:blr · ~200ms window
// STEP 1 — FIND NEARBY DRIVERS
$ GEORADIUS drivers:geo:blr 77.5946 12.9716 5 km ASC COUNT 10 WITHCOORD WITHDIST
GEORADIUS fetches all members of the geo set drivers:geo:blr within 5km of the restaurant at coordinates (77.5946, 12.9716). Results are sorted ASC (nearest first) and limited to 10. WITHCOORD returns actual lat/lng, WITHDIST returns distance.
1) "driver:D4" 0.82 km [77.5812 12.9680]
2) "driver:D2" 1.24 km [77.5900 12.9820]
3) "driver:D7" 2.17 km [77.5760 12.9550]
4) "driver:D1" 3.90 km [77.6100 12.9440]
// STEP 2 — CHECK AVAILABILITY
$ SMEMBERS drivers:available:blr
SMEMBERS returns all members of the Redis Set tracking available drivers in Bengaluru. We intersect this with GEORADIUS results — only drivers who are both nearby AND available are candidates.
1) "driver:D1"
2) "driver:D2"
3) "driver:D4"
4) "driver:D9"
// STEP 3 — ACQUIRE LOCK (atomic)
$ SET agent:D4:lock "order:ORD_2847" NX EX 30
SET ... NX EX 30 is atomic. NX = only set if Not eXists — if another request already locked this driver, this returns nil (no lock). EX 30 = auto-expire in 30 seconds (driver window). This is a distributed mutex using Redis as the coordinator.
OK → lock acquired, driver reserved for 30s
// STEP 4 — RELEASE ON REJECTION
$ DEL agent:D4:lock
If driver D4 rejects (or times out), we call DEL to immediately release the lock. This allows the system to retry with the next-ranked driver without waiting for the 30s TTL to expire. The available set is not modified until acceptance.
(integer) 1 → 1 key deleted, lock released
// STEP 5 — REMOVE FROM AVAILABLE SET
$ SREM drivers:available:blr driver:D4
On acceptance, we remove the driver from the available set. Any concurrent GEORADIUS+SMEMBERS query will no longer see this driver as a candidate. Combined with the lock, this ensures no double-assignment is possible.
(integer) 1 → driver removed from available pool
// Section 06

API Explorer

The real API contract — request and response shapes for all scenarios.

POST /v1/delivery/assign
REQUEST BODY
{ "order_id": "ORD_2847", "restaurant_id": "RST_441", "location": { "lat": 12.9716, "lng": 77.5946 }, "strategy": "nearest", // or "rating" "radius_km": 5, "timeout_sec": 30 }
RESPONSE
200 OK — Driver assigned
{ "delivery_id": "DEL_9821", "driver": { "id": "D4", "name": "Rohit Sharma", "rating": 4.8, "distance_km": 0.82, "eta_min": 4 }, "partner_info": { "vehicle": "Bike · KA01HX2847" }, "latency_ms": 187 }