KatInterview

Design a Real-Time Driver Tracking and Nearby Location Service

System DesignModel answer
MediumModel answerSystem Designsystem-designgeospatialin-memory-database

Last updated

Architect a low-latency ingestion and spatial indexing system for tracking real-time vehicle locations and serving proximity queries at high scale.

Context

A major ride-hailing application needs to render active vehicles on a passenger's map in real time. Simultaneously, hundreds of thousands of online drivers transmit location updates every few seconds.

Design the core real-time tracking and proximity search infrastructure responsible for ingesting continuous vehicle telemetry streams, maintaining driver status, and returning nearby available drivers to rider mobile clients with high throughput and low latency.

Requirements

Functional Requirements

  1. Telemetry Ingestion: Ingest location updates (latitude, longitude, timestamp, driver ID) sent by active drivers every 3 to 5 seconds.
  2. Proximity Search: Return the top $K$ (e.g., 10) closest available drivers within a specified radius (e.g., up to 3 km) given a rider's current coordinates.
  3. Driver Availability State: Maintain driver states (OFFLINE, AVAILABLE, EN_ROUTE, ON_TRIP). Only drivers in the AVAILABLE state may appear in proximity search results.
  4. Stale Record Pruning: Automatically evict or hide drivers who fail to report a heartbeat location ping within a configurable window (e.g., 20 seconds).

Non-Functional Requirements & Scale

  • Ingestion Volume: Support 1,000,000 concurrently active drivers globally during peak usage (~250,000 updates/second).
  • Search Latency: Serve nearby driver queries with a p99 response time under 50 ms.
  • Ingestion Pipeline Delay: Process updates end-to-end within 100 ms.
  • Availability & Consistency: Maintain 99.99% service availability. Maps rendering vehicle locations can tolerate brief eventual consistency (a few seconds), whereas driver assignment during dispatch requires strict protection against double-booking.

Key Design Areas to Address

  1. System Architecture & Pipeline: Ingestion flow from mobile clients down to the spatial engine, as well as the query path.
  2. Spatial Indexing & Partitioning: Evaluate spatial indexing techniques (e.g., H3 vs. Geohash vs. QuadTree) and outline a sharding scheme across physical memory nodes.
  3. Two-Pass Query & Boundary Resolution: Describe how the system handles cell boundary conditions and balances broad cell retrieval with precise distance calculation.
  4. Hot-Spot Mitigation & State Transitions: Address high-density scenarios (e.g., sport arenas, airports) and explain how state transitions (e.g., accepting a ride request) take effect immediately.
  5. Fault Recovery & Consistency: Frame the recovery model for node failures and network interruptions.

Hints

Hint 1

Distinguish between 'display' searches (rendering cars on a rider map) and 'dispatch' matching (reserving a driver for a trip). Map display tolerates eventual consistency, while dispatch requires strict atomicity.

Hint 2

Prefer discrete hierarchical spatial grids (such as H3 or Geohash) over dynamic spatial trees (like QuadTrees) to simplify partition routing and deterministic memory lookups.

Hint 3

For boundary edge conditions, query surrounding neighbor cells (k-rings) before running exact Haversine distance computations on candidate drivers.