Metrics Cardinality and Performance Impact
What you'll learn: How high-cardinality labels can cripple your metrics system and practical strategies to prevent cardinality explosion.
What Is Cardinality?
Cardinality refers to the number of unique time series created by your metrics. Each unique combination of metric name and label values produces a separate time series. For example, http_requests_total{method="GET", endpoint="/api/users", status="200"} is one time series. If you have 5 methods, 100 endpoints, and 10 status codes, you've just created 5,000 time series from a single metric.
Why High Cardinality Kills Performance
Think of each time series like a separate file your metrics system must maintain, index, query, and store. High cardinality causes:
- Storage explosion: More disk space consumed exponentially
- Memory pressure: Indexes and active series held in RAM grow massive
- Query slowdowns: Aggregations must scan thousands or millions of series
- Ingestion bottlenecks: Writing new data points becomes CPU-intensive
A single label with unbounded values (user IDs, IP addresses, email addresses) can create millions of series, bringing Prometheus or similar systems to their knees.
Managing Cardinality
Avoid high-cardinality labels entirely:
- Never use user IDs, session IDs, or email addresses as labels
- Limit endpoint labels to route patterns (
/api/users/:idnot/api/users/12345) - Bucket numeric values (port ranges, not individual ports)
Use relabeling and dropping:
- Drop unnecessary labels at collection time
- Aggregate at the source before shipping metrics
Monitor cardinality itself:
- Track series counts per metric
- Alert on cardinality growth anomalies
Key Takeaway: Cardinality is the silent killer of metrics systems—keep labels low-cardinality by design, never use unbounded values as labels, and actively monitor series counts to prevent performance collapse.