Prompt
How do I keep long-term metrics cheap without losing query speed?
Latest observation
A good pattern is to separate “hot” and “cold” metrics storage and make the query path hit the right one automatically.
Practical approach
1. Keep recent data in a fast store
Use a high-performance TSDB or indexed store for:
- the last 7–30 days
- dashboards
- alerting
- ad hoc investigation
This is where low-latency queries matter most.
2. Compact older data aggressively
For long-term retention:
- roll up raw samples into coarser resolutions
- keep aggregates like
1m,5m,1h - drop high-cardinality dimensions if you don’t need them historically
Example:
- 10s raw for 14 days
- 1m aggregates for 90 days
- 1h aggregates for 1–3 years
This cuts storage dramatically while preserving trend analysis.
3. Use tiered storage
Move older partitions to cheaper object storage or cold disks:
- SSD/HDD for hot data
- object storage for archived/rolled-up data
To keep query speed acceptable:
- query the hot tier first
- only fall back to cold tier when needed
- precompute indexes/metadata for the cold tier
4. Pre-aggregate common queries
If users often ask:
- “avg CPU by service”
- “p95 latency by region”
store those aggregates directly rather than recomputing from raw points every time.
5. Partition by time and shard by cardinality
Good layout helps both cost and speed:
- time-based partitioning for pruning old data quickly
- shard by tenant/service/metric namespace to avoid scanning everything
6. Keep indexes small
High-cardinality labels are the main cost driver. To reduce cost:
- limit label explosion
- normalize dimensions
- avoid storing unnecessary per-request labels
- use bloom filters or inverted indexes only where useful
7. Use downsampling with query rewriting
Have the query engine automatically choose the smallest sufficient resolution:
- if asking for 6 months, use 1h rollups
- if asking for 1 hour, use raw or 1m data
This keeps dashboards fast while avoiding scanning raw history.
If you want the shortest answer
The best way is:
Store recent raw metrics on fast storage, downsample older metrics into rollups, move them to cheap object storage, and have queries automatically use the appropriate resolution.
If you want, I can also give:
- a reference architecture,
- a Prometheus/Thanos-style design,
- or a cost/speed tradeoff table.