Design a Nearest-Timestamp Device Status Service
Design rolling out-of-order device-status ingestion with deterministic nearest-time queries.
Problem statement
Design a service that continuously ingests status records containing officer_id, timestamp, and status data. An active device emits one record every five seconds, but records may arrive out of timestamp order because of network delay.
Given officer_id and a target timestamp, return the temporally nearest retained record for that officer; on an exact-distance tie, return the earlier record. Retain only a rolling twelve-hour window and delete older records automatically.
For this exercise, assume 500,000 active devices, 100,000 records per second, 50,000 queries per second, p99 query latency below 100 ms, events up to ten minutes late, event-time retention, idempotent event IDs, authenticated organization-scoped access, and zone-failure tolerance.
What to build
- Accept an idempotent event-time device status even when it arrives out of order within the lateness policy.
- Return the nearest retained status before or after a target timestamp, choosing the earlier record on an exact tie.
- Enforce a rolling twelve-hour event-time retention window and reject records already outside it.
At scale
- Source-backed behavior: active devices emit every five seconds; nearest-time ties resolve to the earlier record.
- Source-backed lifecycle: keep only a rolling twelve-hour history and automatically remove older records.
- Practice assumption: 500,000 active devices produce 100,000 records and 50,000 queries per second with p99 reads below 100 ms.
- Practice assumption: accept events up to ten minutes late, use event-time retention, and require organization-scoped authorization.