KatInterview

Design an Observability Metrics Pipeline at Scale

System DesignModel answer
HardModel answerSystem Designmetricstime-seriesdistributed-systems

Last updated

Design a distributed system that ingests millions of tagged metric data points per second, enforces cardinality safety, tiers storage by age, and serves dashboard queries under 500 ms.

Context

A large engineering organization runs thousands of microservices and batch jobs across multiple distributed clusters. The infrastructure team needs a centralized observability platform that collects runtime metrics from every service, aggregates them into queryable time series, and powers real-time dashboards and alerting for on-call engineers.

You are asked to design this system end to end.

What to Design

Build a metrics collection and query service that covers the full lifecycle: emission from application code, transport to a central store, storage across multiple retention tiers, and query execution for dashboards.

Functional Requirements

  • Metric primitives: support counters (monotonically increasing values), gauges (point-in-time readings), and histograms or timing distributions.
  • Labeled emission: services attach arbitrary key-value pairs (dimensions) to every metric, allowing slice-and-dice aggregation at query time (e.g., by service, region, status_code).
  • Cardinality guardrails: prevent accidental label explosions — for example, a developer who accidentally puts a UUID or a user ID in a label could create billions of unique time series and crash the store.
  • Expressive queries: support rate calculations, dimension-scoped aggregations (e.g., sum by service), time-range windowing, and percentile queries (p95, p99) over histogram data.
  • Tiered retention and downsampling: keep raw high-resolution data for recent windows, and progressively roll older data up to coarser resolutions for long-term trend analysis.
  • Pipeline self-monitoring: detect and alert on ingestion lag, sample drops, and storage backpressure.

Non-Functional Requirements

  • Durability and availability: the write path must absorb traffic bursts without dropping metrics, and must stay available even if the query layer is degraded.
  • Query latency: typical operational dashboard queries should complete in under 500 ms.
  • Horizontal scalability: the system must scale out as new hosts, containers, and services are added.

Scale Targets

ParameterTarget
Peak ingestion rate2,000,000 data points per second
Active unique time series~10,000,000
Raw resolution (10-second samples)7-day retention
1-minute rollups30-day retention
1-hour rollups1-year retention

Areas to Address

Your answer should cover:

  1. Data model and ingestion path — how metrics are structured, how they travel from client code to storage (push vs. pull, local agents, message bus), and how you handle bursts.
  2. Cardinality detection and enforcement — where in the pipeline you detect and reject label explosions, and what data structures make that efficient at scale.
  3. Storage architecture — how you organize hot in-memory storage, warm immutable block storage, and cold long-term rollup tiers.
  4. Query execution — how queries fan out across tiers, how caching and result splitting keep p99 latency under the 500 ms target.
  5. Fault tolerance — how the system handles ingester crashes, consumer lag, and partial failures without losing data.

A strong answer includes capacity estimates, concrete technology choices with stated trade-offs, and an explanation of why each design decision was made.

Hints

Hint 1

Start with a back-of-envelope calculation: at 10s resolution with 10M series, how many points per second does the steady-state write rate imply? What does that mean for storage over 7 days? These numbers determine whether your bottleneck is bandwidth, IOPS, or memory — and the answer shapes every other decision.

Hint 2

Think carefully about where cardinality enforcement lives. Checking at the SDK catches mistakes early but can be bypassed. Checking at the gateway is fast but approximate. Checking at the ingester is authoritative but expensive. A layered approach using Bloom filters and HyperLogLog at the gateway plus exact counts at the ingester gives you both speed and correctness.

Hint 3

For the query path to hit 500 ms on historical range queries, you need more than fast storage — you need a query frontend that splits large time ranges into day-aligned chunks, caches aligned sub-results, and selects the coarsest resolution tier that still satisfies the query step. Without these, even a well-designed storage layer will be too slow for dashboards.