Storage Backend for a Large-Scale Time-Series Metrics Platform
System DesignModel answerLast updated
Design the storage layer for a metrics platform that ingests 100k points per second, serves tag-filtered time-range queries, downsamples older data and enforces tiered retention.
Build the Storage Layer for an Infrastructure Metrics Platform
Your team is building the storage tier behind an internal observability product. Thousands of microservices emit numeric measurements (CPU utilization, request counts, latency and so on). Engineers use the data for live dashboards, and an alerting engine reads it continuously.
What the system must do
- Ingest about 100,000 data points per second, and remain available during node failures.
- Query by time range (for example, "average CPU over the past hour") and by tags, with the ability to group results by tags such as
host_id,service_nameandregion. - Downsample data once it is older than 24 hours, for example turning 1-minute samples into 1-hour aggregates, to save space.
- Retain full-resolution data for 7 days and the coarser data for 30 days.
Assumptions
- A point is a timestamp, a numeric value and a set of key-value tags.
- Up to 1 million distinct tag combinations (series) can exist.
- Points may arrive up to 5 minutes late.
What to cover in your answer
- Data model: how you represent metrics and tags so filtering is efficient.
- Storage technology: relational, NoSQL or a purpose-built time-series database, and why.
- Partitioning and indexing: how data is split to handle volume and keep reads fast.
- Downsampling: how and when older data is aggregated, and how the retention rules fit together.
Include back-of-the-envelope sizing and call out the trade-offs you are making.
Hints
Hint 1
Start with sizing: 100k points/s is roughly 8.6 billion points per day. Work out whether disk space or write throughput and index size is the real bottleneck once points are compressed.
Hint 2
Separate the identity of a series (metric name plus sorted tags) from its samples. Store tags once per series and use an inverted index from tag=value to series IDs, rather than repeating tags on every point.
Hint 3
Shard by series within immutable time blocks so retention becomes dropping whole blocks. For rollups, store sum, count, min and max per bucket so aggregates stay correct when merged, and only roll up data old enough that late arrivals can no longer touch it.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Size the problem first
- Writes: 100k points/s is about 8.6 billion points/day.
- Series: 1M series at 100k points/s means each series reports roughly every 10 seconds, so the numbers are consistent.
- Raw footprint: a naive point is 16 bytes (8 for timestamp, 8 for value), about 140 GB/day. Time-series compression (delta-of-delta for timestamps, XOR for floats, Gorilla-style) reaches about 1.5-2 bytes per point, so 15-20 GB/day. Seven days is about 130 GB, or about 400 GB with 3x replication.
- Rollups: 1M series x 24 hours x 30 days is 720M rows. At about 32 bytes (min, max, sum, count) that is roughly 25 GB.
Conclusion: disk is cheap here. The hard parts are write throughput, index cardinality and query fan-out.
Interpreting the retention rules: rollups are produced once data is older than 24h. Raw data is kept for 7 days, rollups for 30. Queries beyond 7 days are served from rollups. Say this interpretation explicitly.
2. Interfaces
- Write: batched requests (500-5000 points each), so 100k points/s is only a few hundred requests/s.
- Query: metric, tag filters, group-by, aggregation, time range and step. The storage layer decides whether to read raw data or rollups based on range and step.
3. Data model
Split series identity from samples.
- Series key: metric name plus tags sorted by key, hashed to a 64-bit
series_id. Tags are stored once per series, never per point. Repeating tags on every point inflates storage 10-50x and is the most common mistake. - Inverted index:
tag=valuemaps to a sorted posting list of series IDs.region=us-east AND service=apiis an intersection of two lists. Group-by reads the tag values of the surviving series. At 1M series this fits in a few GB of RAM. - Samples: compressed chunks per series per time block (for example 2 hours).
- Rollup rows:
(series_id, hour_bucket) -> {min, max, sum, count}. Store sum and count rather than the average, since an average of averages is wrong when bucket counts differ. Keep min and max so spikes survive downsampling.
Tags are therefore not columns. They are metadata on the series plus an index.
4. Storage choice
| Option | Assessment |
|---|---|
| Relational (Postgres/MySQL) | B-tree inserts at 100k rows/s with per-row overhead are painful; each new tag means a schema change; DELETE-based retention is expensive. Fine for small scale only. |
| Wide-column (Cassandra, Bigtable) | Strong write throughput, flexible schema. Row key (series_id, time_bucket) holding compressed blobs. No native tag index, so you build one. TTL deletes create tombstones that hurt reads until compaction. |
| Time-series DB (Prometheus-style with Thanos/Mimir, M3, VictoriaMetrics, InfluxDB) | Built-in inverted index, specialized compression, time-block layout, downsampling and cheap retention. Roughly an order of magnitude better storage efficiency. |
Recommendation: a TSDB-style architecture, either adopting one or building the same design over object storage. If the organization already operates Cassandra well, wide-column plus a custom index is a defensible alternative.
5. Architecture
Agents -> LB -> Distributors (validate, hash series_id)
-> Kafka (partitioned by series_id, RF=3)
-> Ingesters (WAL + in-memory head, replicated x3)
-> flush 2h blocks -> Object store + Compactor/Downsampler
Query frontend -> Queriers -> ingesters (recent) + store gateways (old blocks)
Alert evaluator -> Queriers (mostly served from ingester memory)
Kafka absorbs bursts, enables replay after an ingester failure and decouples producers from storage.
6. Partitioning and indexing
- Time first, then series. Data lives in immutable time blocks (2h, later compacted to 1 day). Inside a block, shard by
hash(series_id)with consistent hashing across ingesters. - Never shard by timestamp alone: all current writes would hit one hot shard.
- Retention is cheap: delete whole blocks or object prefixes older than 7 days (raw) or 30 days (rollups). No row deletes, no tombstones.
- Per-block index: a query picks the blocks overlapping its range, intersects posting lists within each, and decodes only matching chunks.
- Scatter-gather queries: push partial aggregation (sum and count per group) to shards and merge. A query frontend splits long ranges by day and caches results.
7. Late data
- Ingesters write to a WAL before acknowledging, so crashes are recoverable.
- Points go to the open in-memory chunk for their series. The head block spans the current window plus a grace period of at least 5 minutes, so late points still hit mutable data.
- Points older than the grace period go to a small out-of-order buffer merged during compaction, or are rejected and counted in a metric.
8. Rollup mechanism
- A downsampler picks up blocks older than 24h. They are sealed and well beyond the 5-minute lateness window, so they never change.
- For each series it streams chunks and emits one row per hour with min, max, sum and count.
- Output is written as a separate rollup block with its own index, so queries with a coarse step (or a range beyond 7 days) read it directly.
- The job is idempotent: the output is keyed by block and bucket, so a retry overwrites rather than duplicates.
- Averages are computed at query time as sum/count. Percentiles cannot be derived from these aggregates; if needed, store histograms or sketches (for example t-digest) instead.
Retention then runs as simple block expiry: raw blocks after 7 days, rollup blocks after 30.
9. Cardinality and operations
- Cardinality is the main failure mode. One unbounded tag (user ID, request ID) can explode the series count. Enforce per-tenant series limits, reject or drop offending tags, and alert on series growth.
- Replicate ingesters 3x and use quorum writes for availability. Object storage gives durable older data.
- Alerting reads mostly recent data, so serve it from ingester memory for low latency.
10. Common mistakes
- Storing tags on every point.
- Averaging averages instead of keeping sum and count.
- Sharding purely by time, creating a hot shard.
- Row-level deletes for retention.
- Rolling up data that can still receive late points.
- Ignoring tag cardinality limits.
Trade-offs to state
Higher replication improves availability but multiplies write cost. Longer head blocks tolerate more lateness but use more memory. Coarser rollups save space but lose detail, which is why min and max are kept.