Deploying a Time-Series Platform: Cardinality Controls, Downsampling, Retention, and Query Guardrails
Deploying a production-grade time-series database (TSDB) like Prometheus, Grafana Mimir, VictoriaMetrics, or InfluxDB requires careful tuning of cardinality, downsampling, retention, and query guardrails. These features prevent storage bloat, query explosions, and OOM kills while enabling efficient long-term analytics. Below, I'll break it down with explanations, best practices, and deployment configs (focusing on Prometheus/Mimir-style YAML for universality).
1. Cardinality Controls
Cardinality = number of unique series (metric name + label combinations). High cardinality (e.g., http_requests{url="/user/123456"}) causes exponential storage growth and slow queries.
Why Control It?
1M series @ 1KB/series = 1GB RAM just for indexes.
Queries scan all series, leading to timeouts.
Best Practices & Deployment
Pre-ingest limits:
Limit label cardinality per metric (e.g., <100 unique values/label).
Use relabeling to drop high-cardinality labels (e.g., user_id, trace_id).
Mimir: Native per-tenant limits via runtime-config or Enterprise.
Deployment Tip: Start with alerts (sum by (metric) (count({__name__=~".+"})) > 1K), enforce via API gateways (e.g., promxy).
2. Downsampling
Downsampling aggregates high-res data into coarser resolutions (e.g., 1s → 5m) for older periods, reducing storage by 90%+ while supporting multi-res queries.
Why Use It?
Raw 1s data for 1 year = petabytes; downsampled = terabytes.
Fast range queries over years.
Best Practices & Deployment
Resolutions: 5m/1h/1d/1w.
Prometheus/Mimir Config (via compactor or querier):