KatInterview

Live Fleet Proximity Lookup with Eligibility Filters

System DesignModel answer
MediumModel answerSystem Designgeospatial-indexstreaming-ingestionkafka

Last updated

Design a service that ingests per-second robotaxi telemetry and answers low-latency radius searches filtered by vehicle eligibility, tolerating late and duplicate packets.

Context

A company runs a driverless ride-hailing fleet across several cities. Dispatchers, remote-assist staff, and routing components must quickly find vehicles close to a point that also satisfy operational conditions such as seat count, charge level, sensor and hardware health, readiness to drive autonomously, or whether the cabin has been cleaned.

Design a fleet proximity lookup service. It continuously consumes live vehicle telemetry and answers geospatial queries restricted to eligible vehicles.

Requirements

Functional

  • Telemetry intake: Each vehicle reports every 1-2 seconds. A report contains position (latitude, longitude), heading, speed, a timestamp, and operational state (battery level, status, occupancy, hardware faults).
  • Proximity query: The caller provides a center point, a radius (up to 5 km), a result limit k, and filters such as status == IDLE, battery >= 30%, wheelchair_accessible == true.
  • Freshness reporting: Every returned vehicle carries freshness information (last update time, an estimate of position uncertainty). Vehicles whose data is older than a configurable limit (for example 10 s) are excluded or explicitly flagged.
  • Late and reordered packets: Delayed or out-of-order messages (typical on cellular links) must be dropped or reconciled so that vehicle state never goes backwards.

Non-functional

  • Scale: 50,000 active vehicles worldwide; up to 10,000 in one dense city.
  • Throughput: about 50,000 telemetry updates/s and about 5,000 queries/s.
  • Latency: query p95 under 30 ms; time from an event being produced to it being searchable under 500 ms.
  • Availability and consistency: 99.99% query availability. The spatial index may be eventually consistent, but a vehicle's state must never regress to an older timestamp.
  • Security and privacy: role-based access control over telemetry and passenger-presence data; internal identifiers masked where appropriate.

What to cover

  1. APIs for streaming ingestion and for the nearby-eligible-vehicles query.
  2. Spatial indexing and storage: in-memory options (S2, H3, quadtree, geohash on Redis) versus durable storage.
  3. Architecture from vehicle gateways through to the serving layer.
  4. Failure modes and hot spots: crowded areas such as an airport queue, dropped cellular connections, node failure, and network partitions.

Hints

Hint 1

Do the sizing first: how many bytes of live state exist for 50,000 vehicles, and for the busiest city? Let the answer decide whether the spatial index needs to be sharded at all.

Hint 2

If a whole city fits in the memory of one machine, consider partitioning by city and replicating the full index to several query nodes instead of splitting a city by cell.

Hint 3

For ordering, avoid trusting wall-clock time alone. Think about a vehicle-generated monotonic key (with a reset marker for reboots) and a compare-and-set rule that makes updates idempotent.

Hint 4

For the query, think of a grid of hexagonal or similar cells: start at the center cell, expand ring by ring, apply cheap categorical filters through per-cell bitmaps, and stop when the next ring cannot beat the current k-th best distance.