Skip to content
SD-10 · Back to the write-up

Design a Distributed Metrics Aggregation

Hash each series to a shard, keep 2 hours in memory, move older blocks with rollups to object storage, and cap series per tenant.

Follow a request

Sources
Edge
Pipeline
Storage
Host agentBatches every 10 s
EngineerDashboards, pages
Ingest gatewayLimits, hashing
Alert evaluatorRules every 30 s
Query frontendSplit + cache
Ingest log6 hours, 3 copies
Stream aggregatorDrops labels
QueriersFan out, merge
TSDB ingesters64 shards × 3
Limits and rulesPer tenant
Object storageBlocks + rollups
CompactorMerge, downsample
1user → frontend · query_range 7d, step 5mAn engineer opens a dashboard. Each panel sends a range query.1 / 6

The numbers, at a glance

One hour of one series……is 360 raw points, or 1 hourly rollup
1 rollup360 raw points
Compression is the whole gameBytes per stored point
Memory holds very little2 hours out of 15 days of raw data
Yet most alerts and many panels read only that 0.6%.

A range query, in order

Finished days come from the cache; only today is computed.

Engineer
Query frontend
Results cache
Querier
TSDB ingesters
Object storage
1 query_range 7d, step 5m
2 get 6 finished days
3 6 hits
4 today
5 last 2 h, 3 copies
6 chunks
7 today’s 1-min blocks
8 chunks
9 today’s series
10 store today (1 min)
11 7 days of points
RequestResponseAsync, does not block

Where to aggregate

The decision this question is really about.

Raw only, at query time
Too slow at scale
store every 10 s point
query sums 3,000 series
30-day panel: seconds
+ Any question later.− 30 days × 3,000 series = 777M points per refresh.
On the agent only
Loses truth
host p99host p99
average of p99s
wrong fleet p99
+ Tiny volume.− Per-host p99s cannot be combined.
Raw + rollups + rules
Our pick
raw 15 days
1-min 60 days1-h 2 years
query picks resolution
+ Recent data flexible, long ranges cheap.− More parts; dropped labels are gone.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 50,000 points/sMake it work
Host agents
TSDB server
DashboardsAlerts
Agents push to one TSDB server that answers every query.
Stage 2 · ≈ 5M points/sShard the writes
Host agents
Gateways
Ingest log
Sharded TSDBObject storage
Hash series to 16 shards × 3, a log in front, old blocks to object storage.
Stage 3 · ≈ 20M points/sFast long ranges
Query frontendResults cache
Queriers
Sharded TSDBObject storageCompactor
Results cache by day, queriers, rollups from the compactor; 64 shards.
Stage 4 · 20M points/s, 100M seriesTame cardinality
GatewaysLimits and rules
Ingest log
Stream aggregatorSharded TSDB
Per-tenant series limits and a stream aggregator that drops unused labels.
Was this walkthrough useful?Your vote tells us what to improve next.