Lesson 5 of 9 · 23m
Retention, Downsampling, and Resolution Tradeoffs
Choose retention and downsampling windows based on questions operators actually ask, not on an emotional attachment to infinite raw fidelity.
Raw high-resolution metrics feel safe because they preserve everything. They also cost money, slow queries, and eventually become impossible to retain. The correct question is not 'how much can we keep?' It is 'which operational questions need which resolution over which time horizon?' Incident response, capacity planning, and audit reporting are different products with different data needs.
Match resolution to decision horizon
A practical resolution model:
0-24 hours 15s or 30s data for incident response
2-14 days 1m or 5m data for trend diagnosis
1-13 months 1h data for capacity and seasonal patterns
beyond 1 year daily aggregates only if a business report needs themIf nobody has ever opened a 15-second-resolution graph from eight months ago, stop paying to retrieve it at that resolution. Downsampled data is not a lesser copy; it is a deliberately selected representation.
Retention in Prometheus is finite and local
Classic Prometheus retention flags look simple:
prometheus --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention.time=15d --storage.tsdb.retention.size=180GBTime and size caps both matter. A cardinality incident can fill disk before the time horizon arrives. Remote-write systems often become the long-term store while local Prometheus remains the fast operational cache.
Downsampling means aggregate semantics
You cannot magically preserve every statistic in one downsampled number. For counters, store rate or increase over the downsample window. For gauges, decide whether min, max, avg, or last matters. Latency histograms should aggregate bucket counts before quantile calculation, not store precomputed percentiles that cannot be combined.
A five-minute downsample record might look like:
sum by (service, status) (
rate(http_requests_total[5m])
)For node capacity, retain multiple aggregate shapes:
avg by (instance) (node_memory_MemAvailable_bytes[5m])
min by (instance) (node_memory_MemAvailable_bytes[5m])
max by (instance) (node_memory_MemAvailable_bytes[5m])Average-only downsampling hides saturation spikes exactly when capacity planners need them.
Thanos and Mimir approaches differ conceptually
Thanos Compactor traditionally creates downsampled blocks at resolutions such as 5 minutes and 1 hour after raw blocks age. Mimir and Cortex-style systems often rely more on recording rules and multi-resolution ingestion patterns. Either way, the trade is the same: spend compute once to produce smaller data so future queries scan less.
Raw fidelity is sometimes required
Do not downsample away evidence needed for fast detection. If a queue drains in 20 seconds during a failure, hourly aggregates are useless for incident reconstruction. Keep short-term raw data locally where queries are cheap, and use long-term aggregates for trends.
Also consider regulatory and billing metrics. If the metric feeds invoicing or compliance evidence, define correctness and immutability requirements separately. Operational dashboards are not automatically acceptable audit records.
Test the query experience, not only the storage size
A retention design is successful when the common queries return within interactive latency budgets. Test these explicitly:
24h service incident dashboard
30d error budget trend
90d capacity growth by cluster
1y seasonal comparisonMeasure query duration, bytes scanned, and the user experience. A technically correct downsampling policy that makes the quarterly graph unusable has failed.
Field notes
- Downsampling precomputed percentiles is mathematically invalid in general; aggregate histogram buckets instead.
- Retention size limits are a safety valve, not a capacity plan.
- Deleting high-cardinality raw data later does not retroactively reduce the memory incident it caused at ingestion.
- Keep metadata explaining downsample resolution; future operators will otherwise compare incompatible windows.
- Backfill and compaction can be expensive. Schedule them like batch production jobs, not invisible magic.
Was this lesson helpful?