Cloudradical

Systems Architecture

Engineering a Low-Latency Radio Taxi and Fleet Dispatch Architecture

The software engineering architecture behind high-concurrency radio taxi and ride-hailing dispatch engines: geospatial indexing with Uber H3 and Redis, low-latency telemetry pipelines, real-time routing engines, and driver race condition locks.

Written by

Mai

Principal Software Architect

/14 min read
Engineering a Low-Latency Radio Taxi and Fleet Dispatch Architecture

Key points

  • High-frequency telemetry from thousands of moving vehicles creates write amplification that quickly exhausts standard relational database spatial indexes.
  • Decoupling real-time location streaming into in-memory Redis geospatial indexes and Uber H3 hexagonal cells reduces database load by over 95%.
  • Dispatch matching must calculate true road-network driving ETA rather than Euclidean straight-line distance to avoid assigning drivers across natural barriers.
  • Distributed atomic state machines and Redis Lua locks are essential to prevent double-booking race conditions during simultaneous passenger requests.

Building an on-demand radio taxi or fleet dispatch platform sounds deceptively simple on paper: track vehicle locations on a map, find the nearest driver when a rider requests a pickup, and send a notification. In production, this problem space sits at the intersection of high-velocity streaming telemetry, sub-second geospatial search, and distributed state coordination.

Consider the numbers for a modest municipal fleet of 4,000 active taxis. If each vehicle transmits an encrypted GPS ping every 3 seconds to ensure smooth map tracking, the backend must ingest, validate, and index 1,333 geospatial writes every single second. Running UPDATE drivers SET location = ST_MakePoint(lng, lat) on a relational PostgreSQL instance under this write volume will saturate disk I/O, trigger table bloat, and bring the platform to a crawl.

Here is the architectural blueprint we use when engineering high-concurrency fleet platforms like Taxziy.

1. The Two-Tier Architecture: Volatile Telemetry vs. Transactional Ledgers

The foundational architectural rule of dispatch systems is the separation of telemetry state from transactional state.

A vehicle’s current location is volatile, ephemeral data. If a taxi transmits coordinates at 14:02:01, its 14:02:04 ping renders the previous coordinate obsolete. Storing ephemeral coordinates in a durable ACID database like PostgreSQL or MySQL is an anti-pattern.

Instead, we split the architecture into two distinct pipelines:

  • The Telemetry Tier (Hot Path): GPS pings are ingested via WebSocket or lightweight MQTT gateways, processed entirely in-memory using Redis Geo and Uber H3, and cached with TTLs. No relational database writes occur on raw pings.
  • The Transactional Tier (Cold Path): Ride states (Requested, Accepted, Arrived, In-Transit, Completed), payment authorizations, invoices, and driver settlement ledgers live in PostgreSQL with strict ACID guarantees and foreign key constraints.

2. In-Memory Geospatial Indexing with Uber H3 and Redis

To match a rider with available taxis in under 300 milliseconds, the dispatch engine cannot perform full table scans across thousands of coordinates.

We use a hybrid indexing strategy combining Redis Geospatial primitives and Uber’s H3 Hexagonal Hierarchical Spatial Index:

  • Redis GEOADD & GEOSEARCH: When a taxi driver app pings, we issue GEOADD active_drivers:city_id lng lat driver_id. Redis stores coordinates in a sorted set backed by a 52-bit integer geohash. Finding all available taxis within a 3-kilometer radius requires a single GEOSEARCH active_drivers:city_id FROMLONLAT lng lat BYRADIUS 3 km ASC, completing in under 2 milliseconds.
  • Uber H3 Hexagonal Binning: We discretize the city into H3 hexagonal cells at resolution 8 (average area ~0.73 km²). Hexagons are mathematically ideal for spatial algorithms because all six adjacent neighbors have an identical center-to-center distance, eliminating the edge distortion of square grids. We track driver density and calculate dynamic surge pricing hex-by-hex.

3. The Matching Engine: Why Euclidean Distance Fails

A naive dispatch algorithm calculates straight-line Euclidean distance using the Pythagorean theorem or Haversine formula and dispatches the closest vehicle. In the real world, this fails catastrophically:

A driver may be 300 meters away in a straight line, but separated from the passenger by an uncrossable river, a one-way highway divider, or a railway track, requiring a 15-minute U-turn. Meanwhile, another driver 1.2 kilometers away has direct highway access and can arrive in 2 minutes.

Our dispatch pipeline executes a three-phase filtering strategy:

  • Phase 1 - Geospatial Candidate Selection: Redis returns the top 20 available drivers within a 3km geofence (takes ~2ms).
  • Phase 2 - Road-Network Routing Matrix: We feed the candidate coordinates and pickup location into an in-memory routing engine (Valhalla or OSRM). The routing engine calculates actual turn-by-turn driving distance and estimated time of arrival (ETA) considering road topology, one-way streets, and turn penalties (takes ~25ms).
  • Phase 3 - Score Optimization: Drivers are ranked by a composite score factoring: ETA, driver acceptance rating, vehicle tier match, and idle time equity (preventing driver starvation).

4. Distributed Lockout: Preventing Double-Booking Race Conditions

What happens when two passengers in the same neighborhood hit "Book Ride" at the exact same millisecond? If both requests query the spatial index concurrently, they will both select the same optimal driver. If both dispatch dispatches concurrently, the driver receives two conflicting requests.

To eliminate race conditions, we enforce atomic state transitions using Redis Lua Scripts and distributed locks:

  • When a driver is selected for dispatch offer, an atomic script transitions the driver state from AVAILABLE to LOCKED with a 15-second TTL.
  • If the lock succeeds, the dispatch offer is pushed to the driver's phone with a countdown timer.
  • If the driver accepts within 15 seconds, the state transitions to ASSIGNED, and a transactional ride record is created in PostgreSQL.
  • If the driver declines or times out, the lock is automatically released, returning the driver to the AVAILABLE pool, and the engine cascades to candidate #2.
“A dispatch engine is a distributed finite state machine. Every vehicle transition must be atomic, idempotent, and backed by lease timeouts to prevent orphaned reservations.”

5. Resilient Real-Time Transport: WebSocket vs. MQTT

Mobile connectivity in moving vehicles is inherently hostile. Vehicles drive into underground tunnels, switch cell towers, and encounter network packet loss.

While browser clients use WebSockets, for our driver mobile terminals we standardize on MQTT over TLS with QoS 1 (At least once delivery). MQTT is designed specifically for constrained mobile networks:

  • Compact Binary Headers: MQTT packets have a 2-byte header overhead compared to heavy HTTP headers, preserving mobile battery and bandwidth.
  • Clean Session Resumption: When a driver emerges from a tunnel, MQTT automatically re-establishes the TCP session, replays queued messages, and syncs missed dispatch events without re-authenticating from scratch.
  • Last Will and Testament (LWT): If a driver’s phone loses battery or suddenly disconnects without sending a graceful logout, the MQTT broker detects the socket drop and broadcasts an LWT message that immediately removes the driver from the active dispatch pool.

6. Anti-Fraud: Map Matching and GPS Spoofing Detection

In dispatch platforms, fare integrity is vital. Malicious drivers frequently attempt two types of fraud: using "mock location" Android apps to simulate proximity to airport queues, or driving jagged routes to inflate fares.

We implement two real-time algorithmic safeguards:

  • Hidden Markov Model (HMM) Map Matching: Raw GPS pings are noisy (urban canyons with tall skyscrapers reflect signals, causing coordinates to drift by 50 meters). We pass raw coordinates through an HMM map-matching algorithm that snaps points to verified OpenStreetMap road centerlines, ensuring accurate fare distance calculation.
  • Physics & Telemetry Anomaly Tripwires: We cross-reference GPS speed deltas against hardware accelerometer data. If a taxi reports traveling 800 meters in 2 seconds (impossible acceleration) or reports zero accelerometer movement while GPS coordinates change, the ping is flagged as mock spoofing and the device is quarantined.

FAQ

Common questions

Why not use PostgreSQL PostGIS for real-time driver tracking?

PostGIS is unmatched for complex spatial analytical queries (like polygon intersections and spatial joins), but relational databases are designed for disk durability. Ingesting 1,500+ location updates per second creates massive WAL write amplification and autovacuum thrashing. Storing volatile pings in Redis Geo and persisting only ride history in PostGIS gives you the best of both worlds.

What is the optimal H3 resolution for taxi dispatch?

Resolution 8 (average hexagon edge length ~461 meters, area ~0.74 km²) is the sweet spot for urban ride dispatch. It is granular enough to reflect neighborhood demand while keeping neighbor adjacency lookups fast and lightweight.

How do you handle routing engine scalability under heavy traffic?

Running full turn-by-turn routing for every candidate on every search is computationally expensive. We self-host an in-memory Valhalla or OSRM instance loaded on dedicated compute with memory-mapped road network graphs. A single 16-core instance can calculate over 20,000 matrix distance pairs per second.

What happens if the dispatch server crashes while a ride is active?

Because ride state transitions are committed to PostgreSQL and synced to Redis with persistent replication, any surviving worker node can immediately resume the ride lifecycle. The driver app continually sends heartbeat pings with the current ride_id, allowing seamless automatic recovery.

Next step

Tell us how we can help you.

Tell us the constraint. A senior engineer will reply with a clear next step.

Start a projectDirect reply from a senior engineer