Cardinality Explosion
You'll learn: How unbounded label values in metrics can destroy your monitoring system's performance and cost you dearly.
What Is Cardinality Explosion?
Cardinality refers to the number of unique combinations of metric labels in your time series database. Every unique combination creates a separate time series that must be stored, indexed, and queried.
Cardinality explosion happens when you add labels with unbounded or extremely high-cardinality values—like user IDs, request IDs, email addresses, or IP addresses—to your metrics. Each new value creates a new time series, multiplying your data exponentially.
The Problem
Imagine you track HTTP requests with this metric:
http_requests_total{endpoint="/api/users", user_id="12345"}
If you have 10 million users making requests, you've just created millions of unique time series—one for every user-endpoint combination. Your metrics database now must:
- Store millions of separate time series
- Index them all for queries
- Consume massive memory and disk
- Slow down drastically or crash
Think of it like a library where you create a separate catalog card for every possible combination of book attributes, including each individual borrower. You'd quickly drown in cards.
The Solution
Use labels for low-cardinality dimensions only—things with bounded, predictable values:
- ✅ HTTP method (GET, POST, etc.)
- ✅ Status code (200, 404, 500)
- ✅ Region (us-east, eu-west)
- ❌ User ID (millions of values)
- ❌ Request ID (unique each time)
- ❌ Email addresses
For high-cardinality data, use logs or traces instead, where they belong.
Key Takeaway: Only use metric labels for low-cardinality dimensions; unbounded values like user IDs cause cardinality explosion, destroying your monitoring system's performance and inflating costs.