← Lessons

quiz vs the machine

Platinum1740

System Design

Cardinality Explosion in Metrics

How a single high variety label can multiply series counts until your TSDB falls over.

5 min read · advanced · beat Platinum to climb

What cardinality is

The cardinality of a metric is the number of distinct series it produces. Because a series is one metric name plus a unique label combination, cardinality is the product of the number of distinct values across all labels.

How it explodes

Add a label with many possible values and the count multiplies. A metric with two services and three status codes is six series. Add a user id label with a million values and you suddenly have millions of series.

High cardinality labels include user id, request id, email, full url, and raw timestamps. These are usually mistakes in metrics.

Why it hurts

  • Each active series consumes memory in the index and ingestion path.
  • Query planning slows as the label index grows huge.
  • Storage and cost balloon, and the database can crash or refuse writes.

How to control it

  • Never put unbounded identifiers in metric labels. Send those to logs or traces instead.
  • Bucket continuous values, for example group latency into ranges rather than exact numbers.
  • Drop or aggregate high cardinality labels at the collector before storage.
  • Monitor series counts so a new label cannot silently explode.

Key idea

Cardinality is the product of label value counts, so unbounded labels multiply series until the metrics store collapses, and bounded labels prevent it.

Check yourself

Answer to earn rating on the learn ladder.

1. How is metric cardinality determined?

2. Which label is most likely to cause cardinality explosion?

3. What is a sound fix for a high cardinality field?