Design a Real-Time Anomaly Detection Service
Design a stateful streaming service that learns or maintains per-stream baselines, evaluates numeric observations in near real time, and publishes reproducible anomaly decisions.
Problem statement
For this exercise, assume a multi-tenant service receives timestamped numeric observations from 100,000 independent time-series streams, with a peak rate of 1,000,000 observations per second. Each stream has one active, versioned detector configuration and baseline snapshot. The service must durably accept observations, evaluate on-time data within 10 seconds for 99% of decisions, and publish an anomaly record containing the stream, event-time window, score, threshold, detector version, and compact evidence. Observations carry unique event IDs, may be duplicated or arrive up to five minutes late, and are evaluated using event-time windows. A decision is provisional until its watermark closes the window; after finalization, later data is retained for audit but must not silently rewrite the published outcome. A finalized window has at most one canonical anomaly outcome per stream and detector version, and retries must not duplicate outward notifications. Raw observations are retained for seven days, while anomaly records, detector versions, and baseline metadata are retained for one year. The deployment is single-region across multiple zones, targets 99.9% availability, and should delay decisions under recoverable overload rather than drop accepted observations. You may choose a conventional statistical or learned detector, but explain its maintained state, calibration, drift handling, and safe version rollout. User-interface design, incident management, and automatic remediation are outside scope.
What to build
- Register immutable detector versions with their parameters and baseline state, then safely activate or roll back one version for a stream.
- Durably accept timestamped observations, deduplicate retries by event ID, and preserve enough event-time information to handle bounded out-of-order delivery.
- Evaluate each eligible event-time window with the correct detector version and persist one reproducible provisional or final anomaly outcome.
- Let operators query anomaly history and send at most one downstream notification for each final anomaly outcome despite retries or replay.
At scale
- The service supports 100,000 active streams and a peak ingest rate of 1,000,000 observations per second.
- Ninety-nine percent of on-time observations must be reflected in an anomaly decision within 10 seconds.
- Observations may be duplicated, arrive out of order, or arrive up to five minutes late; finality follows an event-time watermark.
- Raw observations are retained for seven days, while anomaly records, detector versions, and baseline metadata are retained for one year.
- A single-region, multi-zone deployment targets 99.9% availability and preserves accepted observations during recoverable overload.