KatInterview

Time-Series Telemetry Service with Proximity Search

System DesignModel answer
HardModel answerSystem Designtime-seriesdatabase-designdistributed-systems

Last updated

Build a scalable backend that ingests out-of-order device telemetry and supports efficient queries for the status record nearest to any given timestamp.

Problem Context

You need to design a backend service for handling continuous telemetry streams from field devices. These devices—such as wearable sensors, vehicle trackers, or IoT equipment—send operational status updates containing metrics like location, battery level, and sensor readings.

Due to connectivity constraints, telemetry arrives with significant challenges:

  • Out-of-order delivery: Events may arrive minutes, hours, or even days after they were generated
  • Network retries: The same event may be transmitted multiple times
  • Batch uploads: Devices buffer data during offline periods and upload in bursts when connectivity is restored

Your service must support forensic and auditing applications that need to reconstruct the exact operational state at any historical moment.

System Requirements

Core Functionality

  1. Telemetry Ingestion: Accept status events containing officer_id, device_id, device_timestamp, and arbitrary structured payload data
  2. Proximity Query: Given an officer_id and target timestamp T_query, return the single record whose device_timestamp is temporally closest to T_query
    • Tie-breaking rule: when two records are equidistant from T_query, return the earlier one
  3. Automatic Deduplication: Handle duplicate submissions gracefully without storing redundant data
  4. Time-Based Retention: Automatically expire records older than a configurable window (assume 90 days)

Scale and Performance

  • Active entities: 100,000 concurrent officers
  • Update frequency: One record every 5 seconds per officer
  • Peak ingestion rate: ~20,000 writes/second
  • Record size: Approximately 500 bytes per event
  • Query latency: p99 read latency must stay below 50ms
  • Late arrivals: System must correctly handle data arriving up to 7 days late

Design Constraints

  • Data durability is critical—no acknowledged writes can be lost
  • Late-arriving data must be correctly integrated without corrupting the temporal ordering of existing records
  • The system should handle device clock drift and network-induced timestamp inconsistencies

What to Deliver

Provide a complete system design covering:

  1. API specification: Define the ingestion and query endpoints
  2. Storage architecture: Select appropriate database technology and justify your choice based on the access patterns
  3. Data model: Design the schema, including partitioning strategy and indexing approach
  4. Query algorithm: Explain how you efficiently locate the temporally nearest record
  5. Handling disorder: Describe how out-of-order and late data are managed throughout the pipeline
  6. Edge cases: Address clock skew, deduplication mechanics, and retention implementation

Hints

Hint 1

Consider how time-series databases or wide-column stores handle range queries on a clustering key

Hint 2

Think about whether partitioning by day vs. month affects both query performance and storage efficiency given the per-officer data volume

Hint 3

A single exact-match query cannot find the nearest neighbor—you need to search in both temporal directions