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

Avoiding High-Cardinality Labels

Identifying problematic labels like user IDs or timestamps that create unbounded unique metric series.

Avoiding High-Cardinality Labels

What you'll learn: You'll discover how certain metric labels create explosion of unique time series that can overwhelm your monitoring system.

The Cardinality Trap

When you add labels to metrics, you create a new time series for every unique combination of label values. This becomes dangerous when labels have unbounded or extremely large value sets—what we call high cardinality.

Think of it like filing cabinets. If you label one drawer "HTTP Status," you'll have maybe 10-20 drawers (one per status code). But if you label drawers by "User ID," suddenly you need millions of drawers—one per user. Your filing room explodes.

Common High-Cardinality Culprits

User IDs: Every unique user creates a new series. With millions of users, you get millions of series.

Timestamps: Adding exact request timestamps as labels creates infinite unique values.

Request IDs: Similar to user IDs—practically unbounded.

IP addresses: Can grow to massive numbers, especially with IPv6.

Email addresses or UUIDs: Guaranteed uniqueness means guaranteed cardinality explosion.

Why This Matters

High-cardinality labels cause:

  • Memory exhaustion in your metrics system (Prometheus stores every series in RAM)
  • Slow queries as the system scans millions of series
  • Storage bloat with massive disk usage
  • Eventual system failure when resources are exhausted

The Fix

Instead of http_requests_total{user_id="12345"}, use aggregated dimensions: http_requests_total{user_tier="premium"} or http_requests_total{region="us-east"}.

If you need user-specific analysis, that belongs in logs or traces, not metrics. Metrics excel at aggregate patterns, not individual tracking.

Key Takeaway: High-cardinality labels like user IDs, timestamps, or request IDs create unbounded unique metric series that overwhelm monitoring systems—stick to low-cardinality dimensions with bounded value sets.