METRICS PIPELINE

Millions of points a second, and the dashboard still loads

L318 MINSYSTEM DESIGN
PREDICT

A time-series store keeps one series per distinct label set. Here there are twelve, one per host and endpoint. One host has a slow tail. The dashboard shows the average of the twelve per-series p99s. Compared with the true p99 of all requests, the dashboard is:

A metrics pipeline is agents, an ingest tier and a time-series store. Its cost is set by series, not points: every distinct label combination is a separate series with its own index entry and memory. A label with unbounded values multiplies series by the number of values. The defence sits before the store: an allowlist of labels, so extra labels are dropped and points aggregate into an existing series. That aggregation has to happen in the instrumentation or an agent or ingest tier that sums (stream aggregation, an OpenTelemetry collector). Prometheus relabeling can drop a label but does not add up the samples that then share a label set; they collide. The second trap is at query time. A percentile per series cannot be averaged into a fleet percentile; you keep histograms (or mergeable sketches), add them bucket by bucket, then take the quantile.

▶ SIMULATION
AGENTS (4 hosts)
points sent 0 · scrapes 0
labels: host, endpoint
TIME-SERIES STORE
series: 0 / 60
points stored: 0 · avg per series —
by label set: —
INGEST POLICY
labels: keep all
user_id dropped on 0 points
—
dashboard p99 (average of per-series p99)—
true p99 (all 0 raw samples)—
✓ series count <= budget (60)✓ reported p99 within 5% of true p99
SCHEDULE
01[INGEST]INGEST: store every label set as a series; dashboard averages per-series p99
02[AGENTS]AGENTS: scrape 1: 300 requests observed
03[DEPLOY]DEPLOY: v2.3 adds label user_id to http_request_duration_ms
04[AGENTS]AGENTS: scrape 2: 300 requests observed
05[AGENTS]AGENTS: scrape 3: 300 requests observed
06[DASHBOARD]DASHBOARD: query: p99 latency across all hosts and endpoints
07[INGEST]INGEST: report
Start of keep every label, average p99 scenario. 7 steps.
// v2.3: "let's see latency per user"
latency.labels({ host, endpoint, user_id }).observe(ms);   // one new series per user

// dashboard
avg(p99_by_series)            // average of percentiles: not a percentile

The same deploy and the same 900 requests hit every design. KEEP EVERY LABEL goes from 12 series to 611 in two scrapes after the deploy, about 300 new series per scrape, and its averaged p99 reads 68 ms against a true 330 ms. ALLOWLIST holds 12 series but still averages, reading 419 ms. FIX merges the histograms and lands within 2% of the truth.

BREAK IT NOT YET

Three scrapes into a store that keeps every label set as its own series. Ship the deploy that adds user_id to the latency metric at a moment that pushes the store past its series budget.

GOAL: series count exceeds the budget of 60

FIX IT NOT YET

Make the pipeline survive a high-cardinality label and report an honest p99. ingest must key series only on the labels in policy.allow; mergeHistograms must add histograms bucket by bucket; p99() must be the p99 of all traffic, within 5% of the truth.

Mental model:

Budget series, not traffic: every label is a multiplier, and a label whose values come from users has no ceiling. Decide which labels may exist, and roll everything else up (in the instrumentation or an aggregating agent) before it becomes a series. Store distributions as mergeable histograms or sketches, because the question people ask is always about the whole fleet, and percentiles do not add.

IN PRODUCTION

Prometheus, Mimir, Thanos, M3, Datadog, InfluxDB, Graphite rollups; metric_relabel_configs to drop whole series, sample_limit, stream aggregation in agents and OpenTelemetry collectors, histogram_quantile, native histograms, t-digest and DDSketch. The symptom is a monitoring cluster that falls over after a deploy that did not change traffic.

IN INTERVIEWS

“Design a metrics system for 10,000 hosts.” Sketch agents pushing or being scraped, an ingest tier behind a queue for backpressure, and a sharded time-series store. Size it by active series, not points, and ask what the labels are. Put a label allowlist in the instrumentation or an aggregating agent and a per-tenant series limit at ingest, and send high-cardinality fields to logs or traces. Add downsampled rollups for long retention. For latency, store histograms with fixed buckets and merge before taking quantiles; explain why an average of p99s is not a p99, and mention mergeable sketches as the general answer.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.