Build a Time-Series Observability Pipeline for a Large Fleet
System DesignModel answerLast updated
Design an end-to-end metrics collection and alerting system for tens of thousands of hosts, then go deep on cardinality control, storage layout, or alert evaluation.
The Problem
Your team is responsible for building an internal observability platform. Thousands of hosts, each running one or more services, continuously produce numeric measurements: request throughput, error counts, latency percentiles, CPU usage, memory consumption, and more. Engineers need to visualize trends on dashboards and get paged when something goes wrong.
Your job is to design this system.
You don't need to design every layer in equal detail. Start with a concise end-to-end walkthrough of the whole pipeline, then commit to one or two components and design them with real depth — justify your choices, get concrete on data structures, and name the trade-offs.
Before you start: clarifying questions worth asking
A good design begins by nailing down scale and requirements. Consider questions like:
- How many hosts and services are we talking about? How many distinct metric names does each service emit, and how often?
- Do hosts push their measurements out, or does a central scraper pull from each one on a schedule?
- How long must raw history be retained, and does precision need to stay full resolution for the whole window?
- How stale can a dashboard be before it's a problem? Can an alert evaluation skip a handful of points without meaningful impact?
- Is the scope limited to numeric metrics, or does this platform also need to handle logs and distributed traces?
- When a rule fires, how does the alert reach a person? Does the platform need to group related alerts or support temporary silencing?
Scale to anchor your design
Work from the following rough numbers:
- ~50,000 hosts, each running several services
- Each service emits a few hundred distinct metric names every 10 seconds
- Labels attached to each measurement include at minimum: host identifier, service name, and deployment version
Work out the implied number of active time series and the platform-wide ingest rate before you pick an architecture — those numbers rule out entire categories of design decisions.
What a strong answer looks like
- A concretely-shaped data model for a single measurement, with a worked estimate for total active series and ingest throughput
- A short pipeline sketch (ingest → queue → storage → query → alerts), with an explicit statement of where you're going deep and why
- For a storage deep-dive: how time-series access patterns drive partitioning, what compression is available on raw point data, and how data is downsampled as it ages
- For a cardinality deep-dive: what triggers a label explosion, what specific mechanisms catch or prevent it, and what design decisions bound cardinality by topology rather than user-space identifiers
- For an alerting deep-dive: how evaluation stays both timely and correct as rule and series counts grow, and how missing data points are handled without producing false positives or false negatives
Hints
Hint 1
Start by estimating total active series — 50,000 hosts × hundreds of metrics × a handful of label dimensions multiplies fast. Write that number down before designing anything; it's the single biggest constraint on your storage and query choices.
Hint 2
A label whose value comes from user-facing identifiers (request IDs, user IDs, raw URLs) can silently multiply your series count by orders of magnitude. Cardinality control isn't just a nice-to-have — it determines whether the system stays operational.
Hint 3
When evaluating alert rules, distinguish between 'this series reported zero' and 'this series sent nothing at all.' Treating absent data as a zero makes every ingestion outage look like a sudden drop in errors, which is exactly the wrong behavior.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Step 0: Anchor the design with numbers
Before drawing any boxes, nail down the scale.
50,000 hosts × ~200 metric names × ~5 distinct label value combinations per metric ≈ 50 million active time series. Each emits one point every 10 seconds, so platform-wide ingest is roughly 5 million points per second. A single raw point — timestamp (8 bytes), value (8 bytes), and series key — compresses to something like 2–4 bytes per point with delta encoding, still putting raw storage in the range of tens of terabytes per day before any rollups. These numbers mean: you need distributed storage, you cannot afford a single global index over all label values, and cardinality is the biggest operational risk you'll face.
Pipeline sketch (brief)
Agent → Gateway → Queue → Storage → Query layer → Alerting
A lightweight agent on each host batches points and pushes them to a pool of stateless ingest gateways. Push wins over pull here: at this scale the platform would need to maintain a registry of every ephemeral instance's address to scrape it, which is its own hard distributed systems problem.
Gateways validate incoming points against a known schema, attach platform-level labels (region, agent version), and write to a durable, partitioned message queue keyed by series identifier. A fleet of stream consumers reads from the queue, groups points into time-ordered mini-blocks per series, and flushes them to time-series storage. A query service sits in front of storage and is called by both the dashboard layer and the alert evaluator. Alerts feed into a notification service that handles routing, deduplication, grouping, and on-call silencing.
Single point shape: (metric_name: str, labels: dict[str, str], timestamp: unix_ms, value: float64) — for example ("http.errors", {"host": "h-4821", "service": "checkout", "version": "v2.3"}, 1718000000000, 3.0). The series key is the metric name plus the sorted, serialized label set. Every unique key is exactly one series in storage.
Deep dive 1: Cardinality control
The failure mode is quiet and catastrophic: an engineer adds a label whose values come from an unbounded space (a user ID, a raw request path, a session token), and overnight the active series count multiplies by millions. Memory, index size, and query latency all blow up together.
Defenses at the schema layer. The ingest gateway enforces an explicit allowlist of label names for each metric name. A point arriving with an unlisted label key is either dropped or rejected with a clear error. This makes a bad label addition fail loudly in a staging deploy rather than silently degrading production. Schema changes go through a review step — the same way a database schema migration would.
Live cardinality tracking. For each metric name, maintain an approximate distinct count of active series over a rolling window (a HyperLogLog structure per metric works well and is cheap). When the count crosses a configurable threshold, the platform takes progressive action: first alert the metric's owner, then start sampling or dropping new series that would create a new label combination for that metric. The metric name and the offending label key are surfaced in the alert, so the engineer knows exactly where to look.
Architectural separation of concerns. The deeper fix is recognizing that some questions belong in metrics and some don't. Per-request latency breakdowns and per-user error counts belong in distributed traces or logs — places where high cardinality is expected and the storage model is designed for it. Metrics should reflect the topology of your infrastructure (host, service, availability zone, deployment version), not the identity space of your users. Enforcing that boundary at design time prevents an entire class of cardinality incidents.
Deep dive 2: Storage layout
Time-series workloads have two dominant access patterns: recent data at high resolution (dashboards and alerts query the last hour or day, often with precise timestamps) and old data at coarse resolution (trend queries over months don't need 10-second granularity and would be unusably slow at it). The storage design needs to serve both without wasting money on one.
Partitioning by time. Store data in immutable blocks, each covering a fixed time window (say, one to two hours) for a set of series. Recent blocks are kept hot in a fast tier (in-memory or NVMe-backed). Older blocks are compacted, compressed, and moved to object storage. Queries over a time range only touch the blocks that overlap it — this avoids full scans.
Compression. Consecutive timestamps in a 10-second-cadence series are nearly regular, so delta-of-delta encoding (as used by Gorilla at Meta and by Prometheus) typically brings timestamps down to 1–2 bits per point in the common case. Values compress well with XOR-based encoding when they change slowly. Combined, most real-world metrics compress to 1–4 bytes per point from a raw 16 bytes. At 5 million points per second, that difference is the gap between affordable and not.
Downsampling as data ages. A background compaction job sweeps blocks older than a rolling retention window (say, 3 days for full resolution) and replaces them with downsampled aggregates: for every 5-minute window it stores min, max, sum, and count. These 5-minute blocks are kept for longer (say, 13 months). The query service transparently routes a wide-range query to the appropriate tier. Callers don't need to know — they ask for "error rate over the last 90 days at 5-minute granularity" and get back the right data from the right tier.
Deep dive 3: Alert evaluation correctness
Alert evaluation at this scale means running thousands of rule queries, each potentially touching millions of series, on a repeating schedule. Two distinct problems need to be solved: throughput (doing all that work on time) and correctness in the face of missing data.
Throughput. Partition rules across a pool of workers by rule ID so evaluation is horizontally scalable. Each worker owns a shard of the rule set and executes its queries independently. Stateless workers mean a crashed worker's shard is trivially reassigned.
Correctness with missing points. The subtle failure mode: a data pipeline hiccup means some series don't report for one evaluation window. If the evaluator interprets missing points as zero, an outage in the metrics pipeline looks like every error-rate alert suddenly clearing — the exact wrong behavior when something is already on fire.
The fix is to track expected versus observed report count per series per window. If a series normally reports 6 points per minute and the evaluator sees 0, it marks that window as data unavailable rather than value = 0. Rules evaluated against incomplete windows produce no state transition — they neither fire nor resolve. This prevents a secondary alert storm when the metrics pipeline recovers.
Reducing noise. A single flapping series shouldn't page someone repeatedly. Standard defenses: require a rule to be in a firing state for N consecutive evaluation cycles before sending a notification (this handles transient spikes), and support an inhibition tree where a broader infrastructure alert (a host is down) automatically silences derivative alerts (all services on that host are also reporting errors).
Common mistakes to avoid
- Treating ingest throughput as the hard number without estimating series count first — the series count dominates storage and index costs.
- Using user-space identifiers as metric labels without cardinality guards.
- Mapping missing data to zero in alert evaluation, which inverts alert semantics during outages.
- Designing a single global label index — it becomes a write bottleneck and a query hotspot simultaneously.