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

Metric Cardinality and Labels

Understand how labels add dimensions to metrics and the dangers of high-cardinality label combinations.

Metric Cardinality and Labels

What you'll learn: How labels add powerful dimensions to metrics, and why uncontrolled label combinations can bring your monitoring system to its knees.


The Power of Labels

Labels (sometimes called tags or dimensions) let you slice one metric into many sub-categories without creating separate metrics for each. Instead of defining http_requests_user_service, http_requests_payment_service, etc., you create one metric http_requests with a label service:

http_requests{service="user", status="200"}
http_requests{service="payment", status="500"}

This is elegant and powerful—you can query by any label combination and aggregate flexibly.


The Cardinality Trap

Cardinality is the number of unique label combinations (time series) a metric creates. If you have 3 services, 5 status codes, and 4 regions, that's 3 × 5 × 4 = 60 unique time series for one metric name.

The danger? Labels that produce unbounded or extremely high cardinality:

  • User IDs: millions of users = millions of time series
  • Email addresses: effectively infinite
  • Request IDs or UUIDs: each request creates a new series
  • IP addresses: potentially thousands or more

Each unique series consumes memory and storage in your metrics backend (Prometheus, InfluxDB, etc.). High cardinality causes:

  • Memory exhaustion
  • Slow queries
  • Storage explosion
  • Scrape timeouts

Use Labels Wisely

Good labels: service, region, status_code, method (bounded, predictable values).

Bad labels: user_id, request_id, full_url (unbounded, high-cardinality).

Key Takeaway: Labels multiply your metric's cardinality exponentially—choose low-cardinality, bounded dimensions or risk overwhelming your monitoring infrastructure.