KatInterview

Design a Time-Series Observability Platform

System DesignModel answer
HardModel answerSystem Designtime-seriesmetricscardinality

Last updated

Design a platform that ingests, stores, and queries millions of tagged metric streams per second with tiered retention, cardinality guardrails, and sub-second alerting.

Background

A large-scale application platform runs hundreds of microservices across multiple regions. Every service continuously emits telemetry: request counts, latencies, error rates, queue depths, and more. Your task is to design the centralized observability platform that collects this telemetry, stores it efficiently, and serves it to dashboards, alerting rules, and capacity-planning tools.

Functional Requirements

  • Metric types: counters (values that only increase, like request totals), gauges (point-in-time readings like memory usage), and histograms / timers (distributions that let you compute p50, p95, p99).
  • Labeled dimensions: Every metric can carry arbitrary key-value tags — for example, api_latency_ms{service="checkout", region="eu-west-1", status_code="200"}. Queries must be able to filter and group by any combination of tags.
  • Query and alerting interface: Support aggregations (sum, rate, quantile) across any tag subset over sliding time windows (1 min, 5 min, 1 hour, etc.). Alert evaluation must complete in under one second.
  • Tiered retention with downsampling:
    • Raw resolution: 10-second granularity, retained for 7 days
    • Medium rollup: 5-minute granularity, retained for 90 days
    • Coarse rollup: 1-hour granularity, retained for 1 year

Non-Functional Requirements

  • Throughput: approximately 10 million active time series, translating to roughly 1 million samples per second sustained and 3 million per second at peak.
  • Query latency: dashboard queries over the last 1–6 hours under 500 ms; ad-hoc historical queries spanning 30 days under 3 seconds.
  • Cardinality safety: the labeling system must not allow a runaway tag (e.g., a developer accidentally attaches a unique user ID or a UUID as a tag value) to exhaust index memory and degrade the platform.
  • Resilience: ingestion spikes must not drop critical operational metrics; the system must degrade gracefully.

What to Cover

  1. Data model and ingestion pipeline — how metrics flow from services to storage, including push vs. pull trade-offs, client-side pre-aggregation, and buffering.
  2. Storage design — choice of storage engine, how time series are indexed, how data is compressed, and how immutable blocks are managed.
  3. Cardinality control — concrete mechanisms at each layer to detect and contain high-cardinality label explosions before they cause an outage.
  4. Downsampling and compaction — how rollup pipelines work and why certain aggregations (like percentiles) require special handling.
  5. Query path — how large queries are parallelized and how recently ingested data is served before it is flushed to durable storage.
  6. Failure handling — what happens when ingesters crash, when the buffer is full, or when the metrics platform itself needs to be monitored.

Hints

Hint 1

Before diving into architecture, sanity-check the numbers. 10M active series at a 10-second scrape interval is about 1M samples/sec — not 10M/sec. Stating this correction early signals strong engineering judgment. Then size the storage: at ~1.4 bytes per sample with Gorilla compression, 50 billion samples/day is roughly 70 GB/day raw, or ~210 GB/day with 3x replication. The 7-day raw tier is about…

Hint 2

Separate the index path from the data path mentally. When a sample arrives for an already-known series, it is a fast append — no label parsing, no index write. Only truly new series touch the inverted index. This distinction drives the cardinality threat: each new unique label combination burns index memory. A cardinality leak that inflates 10M series to 100M can exhaust the ~10 GB of index RAM ve…

Hint 3

Percentiles cannot be re-aggregated after the fact — this is a critical constraint for your rollup design. You cannot store a pre-computed p99 and later combine it with another p99 to get a fleet-wide p99. Store histogram bucket counts at every tier instead, so any rollup window can reconstruct accurate quantiles. Similarly, for counters, store reset-adjusted increases rather than raw cumulative v…