Prompt
How do I build a cheap long-term archive for metrics?
Latest observation
A cheap long-term metrics archive usually means: store raw metrics at high resolution for a short time, then downsample and keep compressed summaries for a long time. The main way to keep cost low is to avoid keeping every raw datapoint forever.
Good architecture
1. Separate “hot” and “cold” retention
- Hot storage: recent data, fast queries, higher cost
- Keep raw metrics for 7–30 days
- Cold storage: long-term, cheap, slower queries
- Keep 5m / 1h rollups for months or years
A common pattern is:
- 15s or 1m raw samples for 14–30 days
- 5m aggregates for 6–12 months
- 1h aggregates for 2–5 years
2. Use object storage for the archive
For low cost, use:
- S3
- GCS
- Azure Blob
- or self-hosted MinIO if you want to run it yourself
Object storage is much cheaper than keeping a database full of old metrics.
3. Store in a compact format
Use something like:
- Parquet with compression (
zstdorsnappy) - partitioned by time, metric name, or tenant
- maybe grouped by day/hour
Parquet is great for analytical queries and much smaller than JSON/CSV.
4. Downsample before archiving
For each metric series, store rollups such as:
- min
- max
- avg
- p50 / p95 / p99 if needed
- count
- sum
If you only need trends and not exact raw points, this cuts storage a lot.
5. Partition by time
A practical layout is:
metrics/year=2026/month=10/day=25/...ormetrics/tenant=X/metric=cpu_usage/date=2026-10-25/...
Time partitioning makes retention and queries much easier.
6. Compress aggressively
Use:
zstdfor best compressionsnappyif you want faster reads/writes and acceptable compression
For many metrics workloads, compression makes a big difference.
7. Use retention policies
Automate:
- delete raw data after X days
- move rolled-up data to colder storage
- expire old partitions automatically
This is often the biggest cost saver.
Cheap stack options
Option A: simplest and cheapest
- Ingest into your current metrics system
- Export daily rollups to S3/GCS
- Query archives with DuckDB, Athena, BigQuery, or Spark
Good if you mostly need auditing, reports, or occasional historical analysis.
Option B: open-source TSDB + object storage
- VictoriaMetrics
- Thanos
- Cortex/Mimir
- InfluxDB with retention/downsampling, though object-storage-native systems are often better for long-term archive
This works well if you already use Prometheus-style metrics.
Option C: custom pipeline
- Collect via agent/Prometheus remote write
- Batch into hourly/daily files
- Write Parquet to object storage
- Query with Athena/DuckDB
Good if you want low cost and can build a little plumbing.
Practical design recommendations
If you want “archive, not real-time”
Use:
- object storage
- Parquet
- daily partitions
- rollups only
- serverless query engine when needed
If you need both recent dashboards and long-term history
Use:
- a fast TSDB for recent data
- periodic export/downsampling to object storage
If data volume is huge
Consider:
- cardinality reduction
- label normalization
- sampling certain metrics
- storing only important metrics long-term
- per-tenant quotas
Common mistakes to avoid
- Keeping raw high-cardinality series forever
- Using a relational DB for all historical metrics
- Not downsampling
- Too many labels/dimensions
- Storing uncompressed text
- Not partitioning by time
- No retention/TTL automation
Rough rule of thumb
If you store every 15-second metric forever, costs grow fast.
If you downsample to 5-minute and hourly rollups, long-term storage becomes very cheap.
A solid cheap baseline
If I were designing one from scratch, I’d do this:
- Collect raw metrics
- Keep raw for 14 days
- Generate 5-minute rollups
- Store rollups in Parquet on S3/GCS
- Keep 5-minute rollups for 1 year
- Generate 1-hour rollups
- Keep 1-hour rollups for 3–5 years
- Use Athena/DuckDB for occasional queries
That’s usually a good balance of cost, simplicity, and usefulness.
If you want, I can also sketch:
- a concrete AWS setup
- an open-source stack
- or a schema/layout for Parquet files for metrics archiving.