Understanding Metric Cardinality: Costs, Risks & Fixes


TL;DR: Metric cardinality is the number of unique time series a single metric produces, determined by multiplying the unique values of each label together. High cardinality crashes Prometheus instances, inflates observability bills by tens of thousands of dollars monthly, and degrades query performance. Keeping labels bounded, routing high-variance identifiers to logs, and setting cardinality budgets are the most effective controls.


Every monitoring system has a breaking point, and metric cardinality is usually the thing that finds it. Whether you are instrumenting your first application or debugging why your Prometheus instance just ate 60 GB of RAM, understanding metric cardinality is the single most important concept standing between useful observability and an unpleasant surprise from your finance team.

This guide breaks down what cardinality actually means, why it matters, how it explodes, and what you can do about it, with particular attention to serverless and edge runtimes where the problem has its own unique flavor.

If you are new to metrics concepts, the metrics types overview provides helpful background before diving in here.

What Is Metric Cardinality?

Metric cardinality is the number of unique time series that a single metric creates. Every unique combination of a metric name and its label values produces a separate time series that your backend must store, index, and scan during queries.

The formula is straightforward multiplication:

Cardinality = unique values of Label 1 × unique values of Label 2 × … × unique values of Label N

A concrete example makes this tangible. Say you have a metric called http_requests_total with five labels:

  • method (5 values: GET, POST, PUT, DELETE, PATCH)
  • status_code (10 values: 200, 201, 204, 301, 400, 401, 403, 404, 500, 503)
  • endpoint (100 route templates)
  • instance (50 servers)

That single metric generates: 5 × 10 × 100 × 50 = 250,000 unique time series.

Each of those 250,000 series carries its own RAM, CPU, disk, and network cost. Prometheus says so explicitly in its documentation: “Each labelset is an additional time series that has RAM, CPU, disk, and network costs.”

Cardinality vs. Dimensionality vs. Churn

Three related terms get confused constantly. Here is how they differ:

Concept What it measures Example
Dimensionality The number of labels on a metric Adding a region label increases dimensionality by 1
Cardinality The number of unique time series (all label value combinations) That region label with 20 values multiplies your series count by 20
Churn How fast new series appear and old ones disappear Kubernetes pod restarts create new pod_name series every few minutes

The critical distinction: adding one label increases dimensionality by exactly one, but if that label has millions of unique values (like user_id), cardinality explodes. Practitioners on Reddit’s r/Observability emphasize this point repeatedly: dimensionality is cheap, but unbounded cardinality is what kills your system.

Churn is a separate axis of pain. High churn stresses write paths and compaction. High cardinality stresses memory, index size, and query fanout. You can have both problems simultaneously, and Kubernetes environments often do.

Low, Medium, and High Cardinality: A Classification Framework

Not all labels carry the same risk. The most useful mental model, drawn from the Apache Airflow project’s metric classification system, sorts labels into three tiers based on how bounded their values are:

Tier Description Example labels Typical value count
Bounded (Low) Values come from a fixed, known set of categories status_code, http_method, environment 3 to 30
Semi-bounded (Medium) Not a fixed enum, but naturally limited by your infrastructure service_name, dag_id, task_name, region 10s to 100s
Unbounded (High) Grows with traffic, users, or deployments, with no natural ceiling user_id, request_id, pod_name, client_ip 1,000s to millions

Here is a quick reference for common labels:

Label Cardinality tier Why
http_method Low Fixed set of HTTP verbs
status_code Low ~5 to 10 common codes
environment Low dev, staging, prod
region Low to Medium 10 to 30 cloud regions
service_name Medium Grows with your architecture
pod_name High Ephemeral, changes on restart
user_id High Grows with your user base
request_id / trace_id Very High One per request, effectively infinite

This bounded/semi-bounded/unbounded framework is the fastest way to audit your labels. If you want deeper guidance on choosing label names, the label naming conventions guide walks through practical strategies for keeping values in the bounded range.

Why Metric Cardinality Matters

The consequences of high cardinality fall into three categories, and all of them are painful.

Cost explosions

One practitioner on r/devops shared that their team cut their Datadog bill by almost 40%, saving at least $120,000 per month, after fixing a single unbounded tag that had been silently generating custom metrics. Another team documented a jump from roughly 60,000 to over 1.1 million active time series after adding one poorly chosen label. They only noticed when finance asked why the observability bill had tripled.

Research suggests that high-cardinality metrics can consume 70 to 90% of an observability budget while providing limited operational value.

Performance degradation

When cardinality grows unchecked, memory usage rises, indexes bloat, ingestion pipelines stall, and queries fan out across too many series. One practitioner described how an 8 GB Prometheus became a 60 GB Prometheus over just a few weeks as retention filled up with high-cardinality data. GitLab publicly tracked an issue where a single metric (graphql_duration_seconds) had a cardinality of 89,624, causing measurable performance problems.

Silent failures

What makes cardinality problems especially insidious is that nothing obviously breaks. Dashboards still load. Alerts still fire. Deploys continue. The only early signal is often a cost spike that takes weeks to investigate or queries that suddenly feel sluggish during incidents, which is exactly when you need them most.

For teams concerned about monitoring costs, the cost optimization guide covers strategies specific to hosted metrics services.

How Cardinality Explodes: The Multiplication Trap

The multiplication in the cardinality formula is what catches people off guard. Adding a single new label does not add to your series count. It multiplies it.

Walk through this step by step:

Step Labels Series count
Start http_requests_total with method (5 values) 5
Add status_code (10 values) method × status_code 50
Add endpoint (100 routes) method × status_code × endpoint 5,000
Add instance (50 servers) method × status_code × endpoint × instance 250,000
Add user_id (10,000 users) method × status_code × endpoint × instance × user_id 2,500,000,000

That last step is the cliff. One label with unbounded values turned a manageable 250,000 series into 2.5 billion. This is why practitioners on Reddit’s r/PrometheusMonitoring call it the “multiplier pattern.” Each label does not just add cost, it multiplies the cost of every label that came before it.

Labels to Watch Out For

Certain labels appear over and over in cardinality incident postmortems. Avoid putting any of these in metric labels:

Dangerous label Why Alternative
user_id Unbounded, grows with traffic Send to logs or traces
request_id / trace_id One per request, infinite Always belongs in traces, never in metrics
session_id One per session Send to logs
client_ip Thousands of values Aggregate by subnet or drop entirely
pod_name / container_id Ephemeral, churns on restart Use deployment or service instead
Raw URL path (/users/123) Unbounded Use route templates (/users/:id)
timestamp Infinite by definition Already handled by the time series database
error_message (free text) Unbounded string values Use error codes or categories

The rule is simple: if a label value grows with traffic or users rather than with your architecture, it does not belong on a metric. Route high-variance context to logs and traces instead. For a deeper treatment of instrumentation pitfalls, including label mistakes specific to serverless handlers, that guide covers the most common traps.

Cardinality and Histograms

Counters and gauges produce one time series per unique label set. Histograms are different. Each histogram bucket becomes its own series.

A classic Prometheus histogram with the default bucket configuration produces 14 series per unique label combination (one per bucket boundary, plus _sum, _count, and +Inf). If your label set already generates 1,000 unique combinations, adding a classic histogram turns that into 14,000 series.

Native Prometheus histograms (stable since v3.8.0) collapse this down to one series per label combination, a 14x reduction. If you are running a recent Prometheus version, switching to native histograms is one of the highest-impact cardinality optimizations available.

For JavaScript developers working with counters and histograms, the instrumentation guide for counters and histograms explains how to define these metric types while keeping series counts manageable.

Cardinality in Serverless and Edge Runtimes

Most cardinality guidance assumes you are running Prometheus on long-lived servers with stable hostnames. Serverless and edge environments introduce their own set of cardinality traps that are rarely discussed.

Invocation IDs as labels

Every serverless invocation gets a unique ID. Using it as a metric label creates one new series per function call. For a function handling millions of requests, this is unbounded cardinality at its worst.

Function version labels

Rapid deployments generate new function versions constantly. If function_version is a label, every deploy multiplies your series count. Teams doing continuous deployment can accumulate hundreds of versions in a week.

Per-region fan-out

Edge deployments run across 200+ points of presence. If region or colo is a label, you are multiplying every other label combination by 200+. This is semi-bounded (the number of edge locations does not grow with traffic), but the multiplier is large enough to matter.

No sidecar to pre-aggregate

In traditional infrastructure, you can run a metrics agent as a sidecar that pre-aggregates data before it leaves the host. Serverless runtimes have no persistent sidecar. Your instrumentation code is the only place where label discipline can be enforced. This means getting labels right at the point of recording is not optional; it is the only opportunity you have.

For teams building on Cloudflare Workers or Vercel, designing metric schemas for serverless covers how to structure your metrics to avoid these traps from the start. And understanding how to properly flush metrics in short-lived handlers ensures your bounded metrics actually make it to your backend before the runtime shuts down.

Looking for a metrics backend built for serverless? Distlang Metrics uses row-based pricing instead of per-series billing, so cardinality does not directly inflate your costs. Compare plan features to see how this works in practice.

How to Keep Cardinality Under Control

You do not need to eliminate all labels. You need to keep them bounded. Five strategies cover most situations:

1. Use bounded label values. Replace raw URL paths with route templates. Use status code classes (2xx, 4xx, 5xx) instead of individual codes if full granularity is not needed. Stick to enum-like values wherever possible.

2. Route high-cardinality data to logs and traces. If you need user_id or request_id for debugging, send them to a logging or tracing system. These identifiers are essential for investigation but worthless as metric dimensions.

3. Pre-aggregate with recording rules. A recording rule that sums a metric by service into a new, lower-cardinality metric gives dashboards and alerts a cheap series to query. The original high-cardinality data can have shorter retention.

4. Set cardinality ceiling alerts. Give each high-volume metric a documented cardinality budget. Alert when a metric exceeds its budget. This is the single cheapest piece of observability insurance you can buy. It would have caught the 60K-to-1.1M explosion before finance had to.

5. Aggregate at collection time. OpenTelemetry Views, Prometheus relabel_configs, and similar tools let you drop or collapse labels before data reaches your backend. This is especially useful for labels that are valuable at debug time but not worth the storage cost.

For a broader treatment of these patterns, the metrics instrumentation best practices guide covers bounded instrumentation in detail.

Key Takeaways

  • Metric cardinality is the product of unique values across all labels. It multiplies, it does not add.
  • One unbounded label (like user_id) can turn a well-behaved metric into billions of series.
  • High cardinality drives cost (up to 70-90% of observability budgets), degrades performance, and fails silently.
  • Serverless environments are particularly vulnerable because there is no sidecar to catch cardinality problems after the fact.
  • The fix is label discipline: bounded values in metrics, high-cardinality identifiers in logs and traces, and cardinality ceiling alerts as a safety net.

Ready to instrument with bounded labels? The metrics quickstart guide walks through going from code to dashboard in minutes, with cardinality-safe patterns built in.

FAQ

What is a good cardinality target for a single metric?

There is no universal number, but most practitioners aim to keep individual metrics under 10,000 to 50,000 unique series. The more important principle is that cardinality should be bounded and predictable. If you cannot estimate the maximum series count for a metric before deploying it, that is a warning sign.

How do I find which metrics have the highest cardinality in Prometheus?

Use prometheus_tsdb_head_series to see total series count, and query count by (__name__)({__name__=~".+"}) to get a per-metric breakdown. The TSDB status page (/tsdb-status) also shows the top series-producing metrics and label pairs.

Is high cardinality always bad?

Not inherently. Some use cases genuinely need high cardinality (per-customer SLA tracking, for example). The problem is accidental or unbounded cardinality, where series count grows with traffic rather than with intentional architecture decisions. If the cardinality is expected, budgeted, and your backend can handle it, it is fine.

Why does cardinality matter more than the number of data points?

A data point is just a timestamp-value pair appended to an existing series. Creating a new series, however, requires a new index entry, new memory allocation, and new query overhead. Ten million data points across 100 series is far cheaper than ten million data points across one million series.

How does cardinality affect serverless metrics specifically?

Serverless runtimes generate ephemeral identifiers (invocation IDs, container IDs, function versions) that change constantly. Without a persistent agent to filter these out, they easily end up as labels. Combined with edge deployments across hundreds of locations, serverless environments can produce cardinality explosions faster than traditional infrastructure.

What is the difference between high cardinality and a cardinality explosion?

High cardinality means a metric has many unique series, possibly by design. A cardinality explosion is when series count grows suddenly and unexpectedly, usually because someone added an unbounded label without realizing the multiplicative effect. The explosion is the dangerous event; high cardinality is the state that may or may not be intentional.

Can I fix cardinality problems after they happen?

Yes, but it is more expensive than preventing them. You can drop or relabel metrics using metric_relabel_configs in Prometheus, use OpenTelemetry processors to filter labels in the pipeline, or create recording rules to replace high-cardinality queries. Old series will age out based on retention settings. Prevention through bounded labels at instrumentation time is always cheaper than remediation.