When designing a 10M-metric/sec TSDB, pair 2-hour Gorilla Head blocks + inverted label indexes with Distributor cardinality quotas and associative S3 rollups.
TL;DR30-second simplified summary▾
Distributors enforce per-tenant cardinality caps, Ingesters hold ~101 GB of 2h Gorilla chunks in RAM, and Compactors build 5m/1h {min, max, sum, count} rollups for 360x faster 90-day queries.
(ts, float64) samples to ~1.37 bytes in RAM.label=value posting lists map metric selectors to Series IDs—and why unbounded labels like user_id explode memory.R & E · Requirements, Ingestion & Retention Math.
10M samples/sec x 16 bytes uncompressed = 160 MB/sec = 13.8 TB/day = 5.04 PB/year if stored raw.
Illustrative Sizing: With Gorilla compression (~1.4 B/pt), 10M samples/sec = 14 MB/sec = 1.21 TB/day. A 2-hour hot Head window across 50M active series needs 14 MB/s * 7,200 s ~ 101 GB of compressed chunk RAM (plus ~100 GB for the in-memory inverted label index -> easily served by 16–20 ingester nodes with 32 GB RAM each at RF=3).
Raw Row DB (5 PB/yr) vs. Gorilla Head + Rollup Tiering
- 13.8 TB/day raw writes
- Random B-Tree disk thrashing
- 90d query scans 777K pts/series
- 1.21 TB/day (~11x smaller)
- 101 GB hot 2h Gorilla RAM
- 360x faster 90d rollup scans
S · Storage: Inverted Label Index + 2h Gorilla Chunks.
Users query metrics by label selectors like http_requests_total{env='prod', region='us-east'}. Scanning 50M series names sequentially would take seconds.
Each block maintains an Inverted Index: Postings[(label_name, label_val)] -> sorted uint32[] SeriesIDs. Querying env='prod' AND region='us-east' intersects two sorted posting lists in sub-millisecond time, then reads only the matching SeriesIDs' Gorilla chunks.
Inverted Label Postings -> Series ID Table -> Gorilla Chunks
H & A · Write Path, Replication & Fan-Out Query Engine.
Distributors receive Prometheus remote_write batches, enforce tenant cardinality/rate limits, and hash (tenant_id, metric_labels) onto a consistent-hash ring of Ingesters with RF=3.
Each Ingester appends incoming samples to a local sequential WAL (for crash recovery) and into the series' 2-hour Gorilla chunk. Every 2 hours, Ingesters compact the sealed Head chunk into an immutable block and upload it to S3/GCS. Queriers fan out reads in parallel: t > now - 2h goes to Ingesters; t <= now - 2h goes to Store-Gateways reading S3 blocks.
Distributor -> Ingester (WAL + Gorilla) -> S3 Block -> Querier Merge
D · Detailed Design: Downsampling & Cardinality Protection.
When a buggy microservice accidentally puts a trace_id into a Prometheus label, active series count jumps from 50K to 50M in minutes—crashing Ingesters with OOM.
Protect Ingesters at the Distributor using a per-tenant HyperLogLog / bounded series-cache limiter: reject new series with HTTP 429 once a tenant exceeds its quota. Meanwhile, asynchronous Compactors read raw 2h S3 blocks and emit 5m and 1h rollup blocks storing {min, max, sum, count} per bucket.
Hot 2h Gorilla (10s) -> Cold S3 (10s) -> 5m Rollup -> 1h Rollup
- Problem
- How to keep both 2-hour alerting (<50 ms) and 90-day dashboards (<500 ms) fast at 10M metrics/sec.
- Naive Solution
- Store all 10s raw points in one database and scan raw rows for 90-day graphs.
- Why It Fails
- 90-day queries scan 777,600 points per series, saturating disk/S3 bandwidth and timing out.
- Alternatives
- Raw-only scans vs. Pre-computed
avgrollups vs. Associative{min, max, sum, count}rollups. - Engineering Decision
- Keep 2h Gorilla chunks in Ingester RAM, flush 2h blocks to S3, and compact into 5m/1h
{min, max, sum, count}rollups. - Trade-Offs
- Adds ~15–20% extra S3 storage for rollup tiers in exchange for 360x faster multi-month dashboard queries.
A team pre-computes 1-hour rollups storing only avg_value per hour. When a user queries avg_over_time across 7 days with uneven scrape counts (some hours had 10 samples, others had 360), the dashboard shows wrong numbers. Why?
E & D · Evaluation, Assumptions, Limitations & Glossary.
Sizing assumes a 10s regular scrape interval across 50M active series (~10M/sec) and ~1.4 bytes/point average Gorilla compression.
Assumptions & Limitations: If clients send heavily out-of-order samples (>2 hours late), they cannot append to the active Head chunk and must write to an Out-of-Order (OOO) head block that compacts separately on flush. Inverted index RAM scales with unique label-value pairs, requiring strict per-tenant cardinality quotas.
Distributor -> Ingester (WAL + Gorilla) -> Compactor -> S3 -> Querier
Practice: Make the trade-off yourself.
At 10M samples/sec, why does a TSDB keep 2 hours of Gorilla chunks in Ingester RAM instead of writing directly to S3 on every scrape?