Keep a year cheaply: blocks on object storage
Ingesters hold only the recent hours in memory and every two hours seal that window into an immutable block on object storage, where a compactor merges the three copies replication created and joins small blocks into day-sized ones — which turns long retention from a memory problem into a storage-cost and query-speed problem.
Now that exactly one stream per series lands in memory, the next question is how the cluster keeps months of it without holding it all in memory.
Scene 11
Keep a year cheaply: blocks on object storage
- Watch
- Try it
- Predict
- Capture
How does a metrics cluster keep months of data without holding it in memory? Watch one tenant's two hours travel. An ingester keeps only recent samples in memory, so every two hours it seals that window into a file and uploads it to object storage — the cheap, durable, write-once store build-s3 covered (s3-00). Then watch what the other two ingesters do with the same two hours.
Highlighted lines are the ones running in the diagram right now.
def cut_block(tenant):block = seal(tenant.head) # never edited againupload(bucket, block)keep_local(block, for_="13h")tenant.head = fresh_head()every("2h"):for ingester in owners_of(tenant.series):ingester.cut_block(tenant)
def run():if not compactor_enabled:return # nothing is rewrittenfor window in bucket.windows():copies = bucket.blocks(window)if len(copies) > 1:merge_vertical(copies)for group in adjacent(bucket):merge_horizontal(group) # 2h -> 12h -> 24hfor block in bucket.blocks():if block.age > blocks_retention_period:delete(block) # unset = kept forever
def downsample(block):if not downsampling_enabled:return # Mimir removed this pathif block.age > "40h":coarse = aggregate(block, every="5m")upload(bucket, coarse) # added, not swappedif block.age > "10d":coarse = aggregate(block, every="1h")upload(bucket, coarse) # added, not swapped
Where this sits in Metrics / Monitoring System
Scene 11 of 18, in the Scale out act — Remote-write, ingesters, dedup, blocks, split queries.. Ingesters keep only recent hours in memory and cut immutable two-hour blocks to object storage, where a compactor merges the copies replication created — retention becomes a storage and query-speed problem.
Up next. Now that years of data sit in compacted blocks, the next question is how a 30-day query over them comes back fast.
All 18 scenes in Metrics / Monitoring System · Every curriculum