What it is
A metrics platform collects numeric time series from every host and service (CPU, request rates, latency histograms, queue depths), stores them compactly, answers queries for dashboards, and evaluates alert rules. A series is a metric name plus a unique set of labels, for example http_requests_total{service="checkout", route="/pay", code="500"}; each scrape adds one sample (timestamp, value) to every series.
This case study builds one end to end: requirements and estimates, the ingestion path, its failure under storage stalls and cardinality explosions, the query path, long-term storage, alerting, and a component failure.
Why it exists
Every other system's reliability depends on it. When checkout is slow at 03:00, metrics are how on-call finds out (an alert) and how they find where (a dashboard). That gives the platform unusual requirements: it must keep accepting writes while things around it break, it must stay cheap at very high write rates, and its alerting must notice when it is itself unhealthy.
How it works
Requirements and estimates. Example: 10,000 hosts × ~1,000 series each = 10 million active series. Scraped every 15 s, that is about 667,000 samples per second. Time-series encodings (delta-of-delta timestamps, XOR-compressed floats, as in Facebook's Gorilla paper and the Prometheus TSDB) store a sample in roughly 1–2 bytes, so a day is on the order of 667k × 86,400 × 1.5 B ≈ 86 GB and 15 days ≈ 1.3 TB, before replication. Memory scales with active series: each needs an in-memory head chunk and index entries, a few KB per series in practice, so 10M series is tens of GB across ingesters. All of these are illustrative orders of magnitude.
Ingestion. Agents (Prometheus in agent mode, the OpenTelemetry Collector, vendor agents) scrape or receive metrics and push batches using remote-write. A load balancer spreads them over stateless collectors (also called distributors) that authenticate the tenant, validate and relabel, enforce limits, and hand batches on. Writing synchronously into storage from here couples agent success to storage health. Instead, collectors append to a durable buffer, a replicated log such as Kafka or a write-ahead log on replicated ingesters, and acknowledge. Ingesters consume the buffer, keep recent data in an in-memory head (backed by a WAL), and every two hours cut an immutable block.
Cardinality. Series count is the product of label cardinalities. A label with unbounded values (user id, request id, raw URL, pod name with high churn) multiplies it. Defences sit at the collectors: per-tenant limits on active series and samples per second, per-metric series limits, and relabel rules that drop or aggregate offending labels. Rejected writes return HTTP 429 so the offender sees it. High-cardinality detail belongs in logs and traces, linked from metrics through exemplars.
Query path. Dashboards send PromQL-style range queries to a query frontend that splits long ranges into time-aligned pieces, runs them in parallel, and caches results. Past pieces are immutable once ingestion is complete for that range, so repeated dashboard refreshes hit the cache and only the newest piece or a cold query reaches the queriers. Queriers merge recent data from ingesters with older blocks from object storage.
Long-term storage. Blocks go to object storage. A compactor merges small blocks into larger ones, deduplicates replicas, applies retention, and writes downsampled copies (for example 5-minute and 1-hour resolution, storing min, max, sum and count per window). Typical tiers: raw for days to weeks, 5-minute for months, 1-hour for a year or more. A one-year query at 1-hour resolution reads about 8,760 points per series instead of ~2.1 million raw 15-second samples.
Alerting. A rule evaluator (the Prometheus ruler) runs alert expressions every 15–60 s; a condition must hold for a for: duration before it fires. Rule evaluators run as replicas, so both fire; Alertmanager deduplicates, groups related alerts, applies silences and inhibitions, and routes notifications.
When to use it
Whenever you run more than a handful of services: metrics are the cheapest signal for alerting and capacity planning because they are pre-aggregated. A self-hosted platform like this makes sense at a scale where per-series vendor pricing hurts, or where data residency rules require it; below that, a single Prometheus with a remote backend or a managed service is simpler.
When not to
- For per-request debugging: use traces and logs. Metrics deliberately aggregate away individual requests.
- For business analytics with arbitrary dimensions (per customer, per order): that is an OLAP or event-analytics workload with columnar storage, not a TSDB.
- For a single team with a few hundred hosts: one Prometheus server with local storage handles millions of series; the distributed design is overhead.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Durable buffer before storage | Storage stalls cost delay, not samples | Freshness lag; another system to run and monitor |
| Per-tenant series limits | One team cannot take the platform down | Legitimate growth gets rejected until limits are raised |
| Results cache in the query frontend | Most dashboard load never reaches storage | Cache invalidation for late or backfilled data |
| Downsampling and tiered retention | Long history at low cost and fast long-range queries | Detail lost permanently; rollups must keep min/max to show spikes |
| Push (remote-write) | Central, scalable ingestion; works across networks | No built-in "target is down" signal that pull scraping gives |
Alternatives
- Single Prometheus per cluster with federation or remote-write to a managed backend. Simple; limited by one machine's memory per shard.
- Managed metrics services. No operations; cost grows with active series and samples.
- Columnar analytics stores (ClickHouse-style) for metrics plus events in one place. Flexible queries over high cardinality; less specialised compression and PromQL support.
- Pre-aggregation at the edge (statsd-style or OpenTelemetry views) to cut series before they leave the host.
Failure modes
- Storage stall without a buffer: writes back up into collectors, which reject them; samples are gone for good.
- Cardinality explosion: ingester memory and index size grow until out-of-memory crashes, which then move the series to the remaining ingesters and crash them too.
- Backlog unnoticed: ingestion is intact but minutes behind; alert rules evaluate stale data and miss incidents.
- Silent alerting: missing data makes rules return nothing, so nothing fires exactly when the pipeline is broken.
- Query of death: an unbounded query (all series, one year, raw) exhausts querier memory. Limit series per query, samples per query, and range.
- Collector or ingester failure: stateless collectors fail cheaply if clients retry; ingesters need replication (or the buffer) so their in-memory head is not lost.
In production
Run collectors stateless behind a balancer with health checks; have agents retry with exponential backoff and jitter and keep a local WAL so they can ride out outages. Replicate the buffer or ingest with a replication factor of three across zones. Enforce per-tenant limits from day one and publish them. Alert on the platform's own health: samples/s per tenant, buffer lag, ingester memory, rejected samples, rule evaluation failures. Route an always-firing watchdog alert to an external dead man's switch that pages when it stops. Prometheus, Grafana Mimir, Thanos, Cortex and VictoriaMetrics implement variations of this design.
Common misconceptions
- "Hosts determine cost." Active series do. One label can change cost more than doubling the fleet.
- "A queue fixes overload." It absorbs bursts and stalls; if writes exceed drain rate for good, the backlog grows until the buffer is full.
- "No alerts means everything is fine." It can also mean no data. Alert on absence and on the pipeline.
- "Downsampling is just averaging." Averages hide spikes; good rollups keep min, max, sum and count.
Interview angle
Start with numbers: series, samples per second, bytes per sample, retention, memory per series. Then draw ingestion with a buffer and explain what happens when storage slows down. Interviewers almost always ask about cardinality: name the cause, the limits, and where you enforce them. Cover the query path (splitting, caching), long-term storage (blocks, compaction, downsampling), multi-tenancy, and how alerting stays trustworthy when the platform itself is degraded. Mentioning freshness lag as the price of buffering shows you understand the trade-off rather than just the boxes.
Model assumptions
The simulation is a simplified model, not a benchmark. One simulated request is one remote-write batch of ~5,500 samples, so 120 batches/s stands for ~667k samples/s. Collectors have 8 workers with a 10 ms mean service time; the TSDB has 8 connections, 30 ms writes and 150 ms range reads, and its compaction is modelled as an 8× slowdown. Ingesters have 4 slots each with a 30 ms mean service time, which stands for appending to the TSDB head (about 266 batches/s for two); a TSDB slowdown behind the buffer is modelled as ingesters running 4× slower. The cardinality explosion is modelled as more write traffic (120 → 400 batches/s); index memory growth is described, not simulated. The per-tenant series limit is modelled as a token bucket of 200 batches/s on the collector balancer. The results cache answers a fixed 80% of queries. Health checks run every 500 ms; 2 failures eject, 2 successes restore. Agent retries use up to 3 attempts with exponential backoff and full jitter. Block upload, downsampling, rule evaluation and alert deduplication are scripted illustrations, not simulated. Arrivals are Poisson; service times are lognormal. Utilisation is busy-worker fraction, not CPU.