Low Level Design: Driver Matching Service

What Is a Driver Matching Service?

A driver matching service is the real-time system responsible for pairing a rider’s trip request with the most suitable nearby driver. It must factor in driver proximity, heading, availability, vehicle type, and estimated time of arrival. At scale, this system handles tens of thousands of match attempts per second across geographically distributed regions.

Data Model

The core entities are Drivers and Ride Requests. Driver location data is written frequently and must be queryable by geospatial proximity.

-- Persistent driver profile (PostgreSQL)
CREATE TABLE drivers (
  driver_id     UUID PRIMARY KEY,
  name          VARCHAR(100),
  vehicle_type  VARCHAR(20),   -- 'economy', 'xl', 'premium'
  license_plate VARCHAR(20),
  rating        DECIMAL(3,2),
  status        VARCHAR(20)    -- 'available', 'on_trip', 'offline'
);

-- Ride request queue
CREATE TABLE ride_requests (
  request_id    UUID PRIMARY KEY,
  rider_id      UUID,
  origin_lat    DECIMAL(9,6),
  origin_lng    DECIMAL(9,6),
  dest_lat      DECIMAL(9,6),
  dest_lng      DECIMAL(9,6),
  vehicle_type  VARCHAR(20),
  status        VARCHAR(20),   -- 'pending', 'matched', 'cancelled'
  created_at    TIMESTAMP
);

Driver real-time location is stored in Redis using the native geospatial commands:

-- Store driver location (updated every 4 seconds via mobile SDK)
GEOADD active_drivers <lng> <lat> <driver_id>

-- Query drivers within 3 km of a pickup point
GEORADIUS active_drivers <pickup_lng> <pickup_lat> 3 km ASC COUNT 20

Core Matching Algorithm

When a ride request arrives, the matching service executes the following workflow:

  1. Geospatial candidate fetch: Query Redis GEORADIUS with the pickup coordinates to retrieve the nearest N available drivers (typically top 20).
  2. Filter by vehicle type: Discard candidates whose vehicle class does not match the request.
  3. ETA estimation: For each candidate, compute estimated time of arrival using a road-network graph (pre-computed shortest paths, periodically refreshed). Drivers are scored primarily by ETA, not raw distance.
  4. Heading alignment: Penalize drivers heading away from the pickup point using a dot-product between the driver’s current velocity vector and the vector toward the pickup.
  5. Offer dispatch: Send an offer to the top-ranked driver. Start a 10-second acceptance timer. If the driver declines or times out, advance to the next candidate.
  6. Atomic status transition: On acceptance, atomically set driver status to on_trip in Redis and write the match to the database to prevent double-assignment.

Failure Handling

  • Driver goes offline mid-match: Heartbeat monitor detects stale location updates (>15 s) and removes the driver from the Redis geospatial set. The offer times out naturally.
  • Matching service crash: Ride requests are persisted to a durable queue (Kafka topic). A new matching service instance picks up pending requests on restart.
  • No drivers found: The request is placed in a retry queue with exponential backoff. The rider receives a live wait-time estimate. After 5 minutes with no match, the request is cancelled and the rider is notified.
  • Redis failure: A read replica promotes automatically. In the worst case, the system falls back to a PostGIS proximity query at higher latency.

Scalability Considerations

  • Geo-sharding: Partition the Redis geospatial keyspace by city or geographic cell (H3 hex grid). Each region is owned by a dedicated matching service cluster.
  • Location update throttling: Mobile clients send GPS updates every 4 seconds. A location aggregator service deduplicates and batches writes to Redis, preventing write storms.
  • Horizontal scaling: Matching workers are stateless and scale independently behind a load balancer. Kafka partitions route requests by geographic region to maintain locality.
  • Offer pipeline parallelism: Instead of sequential fallback, send offers to the top 3 drivers simultaneously with a slight stagger (0 s, 3 s, 6 s). The first acceptance wins; others are cancelled.

Summary

The driver matching service combines Redis geospatial indexing for fast proximity lookup, ETA-based scoring for quality matches, and durable queuing for reliability. The key design challenge is achieving low-latency matching (<500 ms end-to-end) while preventing race conditions on driver assignment at high concurrency. Geo-sharding and stateless workers allow the system to scale linearly with demand.

{
“@context”: “https://schema.org”,
“@type”: “FAQPage”,
“mainEntity”: [
{
“@type”: “Question”,
“name”: “What are the core components of a driver matching system design?”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “A driver matching system requires a geospatial index for locating nearby drivers, a matching algorithm (typically proximity-based with scoring for ETA, acceptance rate, and driver rating), a real-time dispatch queue, and a fallback strategy for low-supply scenarios. The system must handle high write throughput as driver locations update every few seconds.”
}
},
{
“@type”: “Question”,
“name”: “How do you handle driver location updates at scale in a matching system?”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “Driver location updates are typically ingested via a dedicated location service using a message queue (e.g., Kafka) to decouple ingestion from storage. Locations are stored in an in-memory geospatial store such as Redis with geohash or S2 geometry cells for efficient proximity queries. Stale locations are expired using TTLs to avoid matching riders to offline drivers.”
}
},
{
“@type”: “Question”,
“name”: “What matching algorithm is commonly used in ride-sharing driver assignment?”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “Most production systems use a combination of nearest-neighbor search filtered by geohash, followed by a scoring function that weights estimated time of arrival (ETA), driver acceptance rate, and trip compatibility. Batch matching using the Hungarian algorithm or a greedy assignment can optimize global efficiency, especially during high-demand periods.”
}
},
{
“@type”: “Question”,
“name”: “How do you design the driver matching system to be fault-tolerant?”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “Fault tolerance is achieved by replicating the geospatial index across multiple nodes, using a distributed lock or compare-and-swap when assigning a driver to prevent double-dispatch, and implementing retry logic with exponential backoff on the client side. Circuit breakers protect downstream services, and a fallback to a degraded matching mode (e.g., broader search radius) ensures availability during partial outages.”
}
}
]
}

See also: Uber Interview Guide 2026: Dispatch Systems, Geospatial Algorithms, and Marketplace Engineering

See also: Lyft Interview Guide 2026: Rideshare Engineering, Real-Time Dispatch, and Safety Systems

See also: Netflix Interview Guide 2026: Streaming Architecture, Recommendation Systems, and Engineering Excellence

Scroll to Top