Course contentsShow
← System Design
Lesson 1192 of 1,91930. Observability: MetricsFree lesson

Cardinality and Label Explosion

Understanding how high-cardinality labels exponentially increase metric storage and query costs.

Cardinality and Label Explosion

You'll learn: How high-cardinality labels can exponentially blow up your metrics storage and cripple query performance.

What Is Cardinality in Metrics?

Cardinality refers to the number of unique time series created by combining metric names with their label values. Each unique combination of labels creates a separate time series that must be stored, indexed, and queried.

For example, if you have an http_requests_total counter with labels {method, endpoint, status_code}, and you track 5 methods × 100 endpoints × 10 status codes, you've just created 5,000 unique time series for that single metric.

The Explosion Problem

High-cardinality labels—like user_id, request_id, or ip_address—create explosive growth. Imagine adding a user_id label to the above metric with 100,000 active users:

  • Before: 5,000 time series
  • After: 5,000 × 100,000 = 500 million time series

This explosion causes:

  • Storage costs to skyrocket (each series needs memory and disk)
  • Query performance to degrade (scanning millions of series)
  • Ingestion bottlenecks (metrics backend can't keep up)
  • Out-of-memory crashes in your monitoring system

The Analogy

Think of metrics like a library catalog. Low-cardinality labels are like organizing by "genre" (10 categories). High-cardinality labels are like organizing by "exact reader who checked it out" (millions of categories). The second approach creates an unmanageable catalog.

Prevention Strategies

  • Use low-cardinality labels (service, region, environment)
  • Avoid unbounded labels (user IDs, timestamps, IP addresses)
  • Use logs or traces for high-cardinality data instead
  • Apply label aggregation where possible

Key Takeaway: High-cardinality labels multiply your time series count exponentially, turning a manageable metrics system into an expensive, slow disaster—keep labels low-cardinality and bounded.