Skip to main content
This article explains how to design Prometheus metrics to avoid cardinality pitfalls that can cripple performance and raise costs. It uses a payment service example to show safe, bounded label usage versus dangerous, high-cardinality labels.

Example: a safe initial design

Imagine a payment service where you want to count every payment processed. You add a counter named payments_processed_total and choose labels that are bounded and predictable:
  • provider (Stripe, PayPal, Square)
  • currency (usd, eur)
  • result (success, declined, timeout)
In the Prometheus/OpenMetrics exposition format, a few example time series look like this:
With 3 providers × 2 currencies × 3 results you end up with 3 * 2 * 3 = 18 distinct time series. Small, bounded, and easy for Prometheus to handle.

What goes wrong: adding unbounded labels

If someone proposes adding per-entity labels like customer_id or transaction_id, the cardinality profile changes dramatically. For example, adding a customer_id label yields time series like:
After only 1,000 unique customers, the 18 original series could expand to roughly 18,000 series. With 1,000,000 customers you could create 18,000,000 series from a single counter (18 × 1,000,000). This explosion is what we mean by high cardinality.
A slide titled "Prometheus Metric Design Anti-Patterns" showing two graphs: the left plots rising cardinality with example high-cardinality labels (Customer IDs, Transaction IDs, UUIDs, Emails, IPs), and the right shows a curve that flattens out to illustrate a capped number of rows.
A useful rule of thumb: if a label can take more than ~100,000 unique values over time, question whether it belongs in your metrics. Prefer bounded labels in metrics and keep high-cardinality identifiers in logs or traces.

What “cardinality” means in Prometheus

Cardinality = the total number of unique time series Prometheus stores. Each unique combination of metric name and label set is a separate time series. For example, all of these are distinct series:
  • payments_processed_total{provider="Stripe", currency="usd", result="success"}
  • payments_processed_total{provider="Stripe", currency="usd", result="success", customer_id="cust_90210"}
  • payments_processed_total{provider="Stripe", currency="usd", result="success", customer_id="cust_90210", transaction_id="txn_a8f3e9"}
Why this matters:
  • Prometheus keeps active time series in memory. Millions of series drastically increase RAM usage and can make your Prometheus server crash and restart.
  • Managed platforms (e.g., Grafana Cloud, Grafana Mimir) often bill based on active series, so one bad high-cardinality label can increase costs dramatically.

Quick reference — Good vs Bad label choices

Concrete mitigation strategies

  • Aggregate at instrumentation time: record counters with only bounded labels (e.g., aggregate per provider/result) and compute per-customer metrics offline if needed.
  • Use logs or tracing for unique identifiers: put customer_id, transaction_id, IPs, emails, and UUIDs in structured logs or traces, not metric labels.
  • Use Prometheus relabeling to drop high-cardinality labels before ingestion (e.g., relabel_configs in scrape configs).
  • Employ recording rules to precompute and store useful aggregations rather than creating many granular series.
  • Use exemplars (OpenMetrics/OpenTelemetry) to link individual metric values to traces without adding the trace ID as a label.
  • Test and measure: deploy a version of your exporter or service with and without the label and compare active series count, RAM usage, and billing.
Avoid adding per-entity identifiers (customer IDs, transaction IDs, emails, IPs, UUIDs) as metric labels. These values belong in logs or tracing systems — adding them to metrics will likely blow up cardinality and can cause outages or huge costs.

Example cardinality calculation

  • Base series: 3 providers × 2 currencies × 3 results = 18 series
  • With 1,000 customers: 18 × 1,000 = 18,000 series
  • With 1,000,000 customers: 18 × 1,000,000 = 18,000,000 series
This linear multiplication is why adding an unbounded label multiplies series count by the number of distinct values.

How to validate in your environment

You can deploy two versions of the same API — one that uses only bounded labels and one that includes an unbounded label — and observe the impact:
  • Monitor active series count (Prometheus prometheus_tsdb_head_series or your managed provider’s metrics).
  • Track Prometheus memory usage and CPU.
  • Compare query latency for common dashboards.
  • Review billing metrics if using a managed metrics backend.
You’ll get the best long-term results by preferring bounded labels for metrics and keeping per-entity uniqueness in logs or traces. Deploy, measure, and enforce labeling guidelines to avoid cardinality disasters.

Watch Video

Practice Lab