Metric cardinality

On this page 7

Metric cardinality is the number of distinct time series that a metric generates, determined by every unique combination of its name and its label (dimension) values. In cloud observability, cardinality is one of the main factors behind the memory use, storage cost and query speed of a metrics backend, so engineers treat it as a resource to be budgeted rather than an incidental property of instrumentation.

A metric such as http_requests_total with labels for method, status code and service may produce a few hundred series. Adding a label that holds user IDs, request IDs or full URLs can multiply that figure into millions. This growth, often called a cardinality explosion, is a frequent cause of slow dashboards, failed ingestion and unexpected monitoring bills.

How labels multiply time series

Cardinality grows multiplicatively, not additively, because each unique set of label values defines a separate series. The theoretical upper bound is the product of the distinct values of every label, although real data usually populates only a subset of those combinations. A time series database stores each series with its own index entry, sample buffer and compressed chunks.

In a pull-based system such as Prometheus, every active series occupies head block memory until it is flushed to disk, and the inverted index that maps label pairs to series grows with every new value. In push-based commercial platforms, the same mechanism usually appears as per-series or per-custom-metric pricing. The table below shows how quickly a single metric can grow.

Labels on the metricDistinct valuesMaximum series
service2020
service, method20 x 5100
service, method, status20 x 5 x 121,200
plus pod namex 40 pods48,000
plus user IDx 100,000 users4.8 billion
Series count for one request metric as labels are added

The jump at the last row explains why practitioners speak of unbounded labels: any dimension whose values are not drawn from a small, known set can push a metric beyond what any backend handles economically.

Sources of high cardinality in cloud environments

Cloud-native platforms raise cardinality on their own, even with careful instrumentation, because infrastructure identities are ephemeral. Kubernetes assigns new pod names on every rollout, autoscaling creates and removes instances, and serverless functions produce fresh execution environments. Each new identity creates new series while old ones go stale, a pattern known as series churn.

Churn matters because the backend must index every series that existed during the query window. A deployment that replaces 200 pods ten times a day can leave thousands of short-lived series that still count toward retention and query cost. The following table lists common label sources and their typical risk.

Label sourceCardinality riskUsual recommendation
HTTP method, status classLow and boundedKeep as labels
Region, availability zoneLow and boundedKeep as labels
Pod or container nameMedium, high churnKeep only where needed
Raw URL pathHigh, unboundedReplace with route template
User, session or trace IDExtreme, unboundedMove to logs or traces
Error message textHigh, unpredictableMap to error codes
Typical label sources and their cardinality risk

Libraries and exporters can also introduce cardinality silently. Auto-instrumentation in OpenTelemetry SDKs, service mesh proxies and cloud provider exporters often attach many attributes by default, so teams should review the effective label set after enabling them.

Metric cardinality compared with logs and traces

Metrics are designed for aggregated, low-dimensional data that can be stored cheaply and queried quickly over long periods. Logs and traces, by contrast, store individual events and therefore tolerate high-cardinality fields such as request IDs, because they are indexed and priced per event rather than per series.

Choosing the right signal is therefore the first defense against cardinality problems. The comparison below summarizes how each signal behaves when a field has many unique values.

SignalCost driverFit for unique identifiers
MetricsNumber of active seriesPoor
LogsVolume of ingested eventsGood
TracesNumber of spans and sampling rateGood
ExemplarsFew sampled references per seriesGood, as a link only
How observability signals handle high-cardinality fields

Exemplars offer a useful bridge: they attach a sample trace ID to a metric data point without making that ID a label. An engineer can then jump from a latency spike to a representative trace without adding a series per request.

Controlling cardinality in practice

Effective cardinality control combines design rules at instrumentation time with enforcement in the pipeline. Prevention is cheaper than cleanup, because removing a label after dashboards and alerts depend on it requires coordinated changes across teams.

  • Bound every label: use route templates such as /orders/{id} instead of raw paths, and status classes instead of free text.
  • Drop or relabel at ingestion: Prometheus relabeling rules and OpenTelemetry Collector processors can remove or rewrite attributes before storage.
  • Aggregate before storing: recording rules and streaming aggregation keep service-level series and discard per-pod detail.
  • Set hard limits: per-target sample limits and per-tenant series limits stop a single faulty deployment from overloading the backend.
  • Monitor the monitor: track active series per metric and alert on sudden growth.

The decision table below helps teams decide what to do with a proposed label before it reaches production.

SituationRecommended actionReason
Fewer than about 50 known valuesKeep the labelLow and predictable cost
Hundreds of values, needed for alertsKeep with a series limitValue justifies a controlled cost
Values grow with users or requestsUse logs or tracesSeries count would be unbounded
Needed only for rare investigationsUse exemplars or samplingDetail available without permanent series
Decision guide for a proposed metric label

Limitations, trade-offs and common mistakes

Reducing cardinality always trades analytical detail for cost and reliability. Removing the pod label, for example, makes it harder to find a single misbehaving replica, and aggressive aggregation can hide problems that affect only one tenant. The right level depends on which questions the team must answer during an incident.

Some newer backends based on columnar storage claim to handle high cardinality better, and they often do, but they shift the cost to query-time scanning and storage volume instead of eliminating it. No architecture makes unbounded labels free.

  • Assuming the theoretical product is the real count: actual cardinality is usually lower, so measure active series instead of guessing.
  • Ignoring churn: short-lived series from deployments can dominate cost even when the active count looks stable.
  • Fixing symptoms in dashboards: aggregating in queries does not reduce what is stored or billed.
  • Copying labels across all metrics: a label useful on one metric rarely belongs on every metric in a service.

In simple terms

Think of a metric as a set of counters on a wall. Each label is a way of splitting one counter into several smaller ones, such as one counter per server or per error type. Metric cardinality is simply how many counters end up on the wall.

Splitting by a handful of servers is fine. Splitting by every customer would require millions of counters, and the system that stores them becomes slow and expensive. Good monitoring keeps the number of counters small and puts per-customer detail into logs or traces instead.

A practical example

An online retailer runs about 60 microservices on Kubernetes and stores metrics in a Prometheus-compatible backend. After a release, a developer adds the full request URL as a label on the latency histogram so that slow product pages can be identified. Because product URLs contain item numbers, the histogram, which already has around 15 buckets per series, grows from roughly 40,000 series to more than 3 million active series within two days.

Ingestion begins to lag, dashboards time out and the monthly metrics bill is forecast to triple. The platform team finds the culprit by ranking metrics by series count, replaces the raw URL with a route template label, and attaches trace IDs as exemplars for slow requests. The series count falls back to about 45,000, and engineers can still open a representative trace for any latency spike, so the investigation capability is preserved at a fraction of the cost.