Build a Time-Series Telemetry Platform for Microservice Fleets
System DesignModel answerLast updated
Design a platform that ingests a million telemetry points per second, keeps 30 days of history, and serves dashboard aggregations in under half a second while staying highly available.
Scenario
Your organization runs thousands of microservices. Each one regularly emits numeric measurements such as CPU utilization, request latency, and error counts. You are asked to design a central telemetry platform that gathers these measurements, keeps them for a month, and powers dashboards that engineers rely on during incidents.
What the platform must do
- Ingest. Services push measurements over an HTTP endpoint (for example
POST /v1/metrics). - Retain. Keep every measurement for 30 days.
- Query. Offer a read API that returns aggregated values over a chosen time window, such as "average latency of service X during the past hour".
Quality targets
- Throughput: sustain about 1 million data points per second.
- Read latency: typical dashboard queries finish in under 500 ms.
- Availability: the platform is itself the tool used to diagnose outages, so it must remain highly available.
What to cover in your answer
- Data model: how a single measurement and its identifying labels are represented.
- Architecture: the main components from the entry point through to the query layer, and how data flows between them.
- Storage approach: which kind of database you choose and why, plus how data is compressed and downsampled as it ages.
- Trade-offs: how you balance consistency against availability in a system dominated by writes.
Support your choices with rough capacity estimates.
Hints
Hint 1
Start with arithmetic: points per second times seconds per day, then bytes per point before and after compression. Also estimate how many distinct series exist given the reporting interval.
Hint 2
Put a durable buffer (a partitioned log) between the stateless ingestion tier and the storage tier so bursts and storage restarts do not lose data. Think about what the partition key should be.
Hint 3
Decide which aggregates survive downsampling. Averages of averages and averaged percentiles are wrong, so keep components (sum, count, min, max) or mergeable sketches, and have the query layer pick a resolution based on the requested window.
Hint 4
For the consistency discussion, ask what is worse for an on-call engineer: a dashboard a few seconds stale, or a gap in the data. Then explain how idempotent writes make retries safe.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing first
- Write rate: 1M points/s sustained, with headroom for 2-3x bursts during deploys and incidents.
- Series count: if each source reports every 10 s, 1M points/s implies roughly 10M active series (a series is a metric name plus a unique label set).
- Daily volume: 1M x 86,400 = about 86.4B points/day.
- Raw size: 16 bytes per point (timestamp + float) gives about 1.4 TB/day, or about 41 TB over 30 days.
- Compressed size: delta-of-delta timestamps plus XOR-encoded floats reach about 1.5 bytes/point. That is about 130 GB/day and about 4 TB for 30 days, or about 12 TB with 3 replicas.
- Ingress: about 100 bytes/point on the wire before batching and gzip means roughly 100 MB/s, easily spread across a stateless tier.
- Reads: hundreds to low thousands of queries/s, many from auto-refreshing dashboards.
Conclusion: append-only, extremely write-heavy, with time-range reads. A purpose-built time-series database fits.
2. API
POST /v1/metricstakes a batched, compressed body: a list of series, each with a name, labels, and[timestamp, value]pairs. Return202only after the batch is durably enqueued. Clients batch (for example every 10 s or 1,000 points) and retry with backoff.GET /v1/querytakes an expression, start, end, and step, and returns labeled series of[timestamp, value].
3. Data model
- Series identity: metric name plus sorted labels, hashed to a 64-bit
series_id. - Sample:
(series_id, timestamp, value). - Inverted index:
label=valuemaps to a posting list of series IDs. A selector with several labels is answered by intersecting lists. - Chunks: per-series samples grouped into 2-hour immutable chunks.
Cardinality is the main hazard. Every unique label combination is a new series costing index memory (about 1-4 KB in the in-memory head). Defenses:
- per-tenant series limits,
- rejecting unbounded labels (user ID, request ID), which belong in logs or traces,
- recording rules that pre-aggregate away high-cardinality dimensions.
4. Architecture
Agents/services -> Load balancer -> Ingestion API (auth, validate, rate-limit)
-> Partitioned log (key = hash(series_id), RF=3)
-> Storage writers (consumer groups)
-> TSDB shards (WAL + in-memory head, RF=3)
-> every 2h flush immutable blocks -> Object storage
Query frontend (split by time, cache) -> Queriers (fan-out + merge)
Rule evaluator -> Alerting
- Log buffer: absorbs spikes, decouples ingestion from storage, allows replay after a writer failure, and lets other consumers (streaming alerts) subscribe. Partitioning by series hash keeps each series ordered.
- TSDB shards: each owns a hash range. A write goes to a write-ahead log, then to the in-memory head. Recent data, which is queried most, is served from RAM.
- Query path: the frontend splits long ranges into per-day sub-queries and caches completed ones, since closed intervals never change. Queriers fan out to shards and object-store blocks and merge partial aggregates.
5. Storage choice and downsampling
| Option | Verdict |
|---|---|
| Relational DB | B-tree maintenance at 1M inserts/s is costly, per-row overhead is 30+ bytes, no native downsampling. Poor fit. |
| Wide-column store | Workable with (series_id, time_bucket) keys, but you must build compression, label index, and aggregation. |
| TSDB | Per-series compression (~10x), label index, time-aligned blocks. Retention is cheap: drop whole blocks past 30 days. |
Tiers:
| Tier | Resolution | Retention |
|---|---|---|
| Raw | 10 s | 7 days |
| Rollup | 1 min | 30 days |
| Rollup | 1 hour | 30 days |
Store min, max, sum, count per bucket, not the average, because sum/count composes across buckets while averaging averages does not. For percentiles, store histograms or mergeable sketches (DDSketch, t-digest); p99 values cannot be averaged.
Meeting 500 ms: averaging latency over 500 hosts for one hour is 360 x 500 = 180K points from memory: fast. Thirty days of raw data would be about 130M points: too slow. Thirty days from hourly rollups is 720 x 500 = 360K points: fast. The query engine chooses the coarsest tier that still gives enough points for the requested step, since a chart rarely needs more than about 1,000 points per line.
6. Consistency vs. availability
Telemetry tolerates slight imprecision far better than gaps during an outage, so favor availability, especially on writes.
- Write path: log with
acks=alland a min in-sync replica count of 2; TSDB replication factor 3 with write quorum 2 and hinted handoff for a down replica. - Idempotency: writes are keyed on
(series_id, timestamp), so client retries and log replays deduplicate safely. - Reads: eventual consistency is fine; a few seconds of lag is acceptable. Queriers read any healthy replica and deduplicate overlapping samples.
- Late data: accept out-of-order points within a bounded window (say 1 hour) and reject anything far in the past or future.
- Cost: replicas can briefly disagree, and a rollup computed before late points arrive may be slightly off. Re-run compaction for affected windows to fix it.
7. Failure handling and operations
- Stateless ingestion scales horizontally and fails over via the load balancer.
- If storage is down, the log keeps accepting data until retention runs out; size it for hours of backlog.
- Monitor the monitor: run a small independent instance that watches this platform's lag, error rate, and series growth, so you are not blind when it fails.
- Multi-region: run a platform per region and federate rollups for global views.
Common mistakes
- Skipping capacity math, so compression and memory choices look arbitrary.
- Ignoring label cardinality, the most common real-world cause of outages in such systems.
- Storing averages in rollups, or averaging percentiles.
- Using a relational database for raw samples.
- Acknowledging writes before they are durable, or demanding strong consistency and sacrificing availability when it matters most.