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 metric | Distinct values | Maximum series |
|---|---|---|
| service | 20 | 20 |
| service, method | 20 x 5 | 100 |
| service, method, status | 20 x 5 x 12 | 1,200 |
| plus pod name | x 40 pods | 48,000 |
| plus user ID | x 100,000 users | 4.8 billion |
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 source | Cardinality risk | Usual recommendation |
|---|---|---|
| HTTP method, status class | Low and bounded | Keep as labels |
| Region, availability zone | Low and bounded | Keep as labels |
| Pod or container name | Medium, high churn | Keep only where needed |
| Raw URL path | High, unbounded | Replace with route template |
| User, session or trace ID | Extreme, unbounded | Move to logs or traces |
| Error message text | High, unpredictable | Map to error codes |
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.
| Signal | Cost driver | Fit for unique identifiers |
|---|---|---|
| Metrics | Number of active series | Poor |
| Logs | Volume of ingested events | Good |
| Traces | Number of spans and sampling rate | Good |
| Exemplars | Few sampled references per series | Good, as a link only |
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.
| Situation | Recommended action | Reason |
|---|---|---|
| Fewer than about 50 known values | Keep the label | Low and predictable cost |
| Hundreds of values, needed for alerts | Keep with a series limit | Value justifies a controlled cost |
| Values grow with users or requests | Use logs or traces | Series count would be unbounded |
| Needed only for rare investigations | Use exemplars or sampling | Detail available without permanent series |
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.