Prompt
How do I choose retention and downsampling settings for time-series data?
Latest observation
Choosing retention and downsampling depends on what questions you need to answer later, how often the data is queried, and how much storage you can afford.
1) Start with your use case
Ask these questions:
- What is the finest detail you need?
- Per-second metrics for debugging?
- Per-minute averages for dashboards?
- Hourly/daily trends for reporting?
- How long do you need each level of detail?
- Recent data is usually queried at high resolution.
- Older data is usually used for trends, not exact values.
- What queries must remain accurate?
- Min/max spikes?
- Averages?
- Percentiles?
- Raw event reconstruction?
2) Use retention tiers
A common pattern is to keep:
- Raw/high-resolution data for a short time
- Aggregated/downsampled data for longer periods
Example:
- 1-second data kept for 7 days
- 1-minute aggregates kept for 30 days
- 1-hour aggregates kept for 1 year
This gives:
- fast recent debugging
- cheaper long-term storage
- enough history for trends
3) Match downsampling to the metric
Downsampling isn’t just “average everything.”
Choose aggregates based on metric type:
- Counters / rates
- store
sum,rate, ordelta
- store
- Gauges
- store
avg,min,max, maybelast
- store
- Spiky metrics
- keep
maxas well asavg
- keep
- Latency / distributions
- keep histogram buckets or quantiles if possible
If you only store averages, you may lose important spikes.
4) Choose intervals based on query patterns
A good rule:
- Pick an interval that is smaller than the granularity users usually inspect
- Keep enough points for charts to look meaningful
Example:
- If users view 24-hour charts on a 1000-pixel screen, ~300–1000 points is often enough
- For a 24-hour chart:
- 1-minute resolution = 1440 points
- 5-minute resolution = 288 points
- 15-minute resolution = 96 points
So 5-minute aggregates might be a good compromise.
5) Retention should reflect business value
Keep data longer if it is:
- needed for compliance
- useful for audits
- expensive to recreate
- important for historical trend analysis
Delete data sooner if it is:
- high-volume but low-value
- only useful for short-term debugging
- redundant after aggregation
6) Storage cost vs fidelity tradeoff
Higher resolution means:
- more storage
- more ingestion cost
- slower queries
Downsampling reduces storage, but you lose detail.
So optimize around:
- recent raw detail
- older summarized history
7) Practical starting point
If you don’t know where to start, try this:
- Raw data: retain 7–14 days
- 5-minute aggregates: retain 30–90 days
- 1-hour aggregates: retain 1–2 years
Then adjust based on:
- query frequency
- storage growth
- whether users complain about missing detail
8) Test with real queries
Before finalizing, evaluate:
- Can common dashboards still be built?
- Are spikes visible?
- Are averages stable?
- Is storage acceptable?
- Are queries fast enough?
9) Avoid common mistakes
- Downsampling too aggressively too early
- Keeping only averages and losing spikes
- Using one retention policy for all metrics
- Not aligning intervals to charting/reporting needs
- Forgetting that some data is more valuable later than it seems now
Rule of thumb
A good policy is:
Keep raw data only as long as you need high-resolution debugging, then keep progressively coarser aggregates for longer-term analysis.
If you want, I can also help you design a retention/downsampling policy for a specific workload, like application metrics, IoT sensor data, or financial time series.