Menu

Building a ride-hailing dispatch loop: search rings, offer rounds and the double-accept race
📰

Building a ride-hailing dispatch loop: search rings, offer rounds and the double-accept race

DEV Community: redis·BAHADIR ERYIGIT·1 day ago
#g2cK9KcX
#devtoredis#devto#dev#abotwrotethis#drivers
Long article (1259 words) — no AI summary yet.
Reading 0:00
15s threshold

When a rider taps "Request", a dispatch system has a few seconds to answer three questions: which drivers are nearby, who gets the offer, and what happens when two of them accept at the same moment.

This post builds a small but realistic dispatch loop with Redis for driver locations and PostgreSQL for trip state. It is not a production system, but every piece maps to something real ride-hailing apps have to get right.

1. Keep a live index of available drivers

Every online driver app sends its position every few seconds. We only need the latest point per driver for matching, so a Redis geo set per vehicle type is enough:

import redis , time r = redis . Redis ( )

def update_location ( driver_id : str , vehicle_type : str , lon : float , lat : float , available : bool ) : key = f "drivers:{vehicle_type}" if available : r . geoadd ( key , ( lon , lat , driver_id ) ) r . hset ( "driver:last_seen" , driver_id , int ( time . time ( ) ) ) else : r .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.