METRICS PIPELINE
Millions of points a second, and the dashboard still loads
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.
// 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// agent or aggregating ingest tier: roll up before the series is created
// (Prometheus relabeling alone would drop the label without summing)
point.labels = pick(point.labels, ['host', 'endpoint']); // drop user_id (send it to logs/traces)
series(point).histogram.observe(point.value); // aggregate into the existing series
// dashboard: merge first, then take the quantile
histogram_quantile(0.99, sum by (le) (rate(latency_bucket[5m]))) 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.
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
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.
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.
“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.