{"canonical_url":"https://engineer.company/glossary/cardinality/","content_markdown":"# Metric cardinality\n\n## What it is\n\nMetric cardinality describes how many distinct time series a metric can produce\nwhen its dimensions take different values. A request counter could have\ndimensions for method, route and status. Each observed combination can create a\nseparate series. Those dimensions make the counter useful for questions about a\nroute or type of result. They also influence how much data the monitoring system\nkeeps and processes.\n\nThe number of values in one dimension matters together with the existing\ndimensions. If an application adds an individual order identifier to a metric,\nit can produce a new combination each time a different order is processed. It\nmay create many series even if the service has only a few routes. A value that\nchanges frequently can cause series churn. The number active at a particular\nmoment and the number that appear over a longer period answer different\nquestions.\n\nEvery monitoring system defines the details of how it identifies a series and\napplies limits. In the Prometheus model a metric name and its set of label\nvalues identify a series. OpenTelemetry metric processing can apply limits to\ndistinct attribute combinations. Read the configuration and check which\nattributes are added by instrumentation, collectors and the backend, because all\nthose stages can affect what finally arrives.\n\n## Why it matters\n\nOperators need enough dimensions to diagnose real changes. A request metric\ndivided by a stable route template might reveal that repeated failures affect\nexports. If the application records every actual URL as a label, a route\ncontaining an order ID can create thousands of separate series from that same\npattern. The useful group remains the route. An individual identifier is often\neasier to examine in a carefully controlled trace or log.\n\nHigh cardinality can affect more than storage. The monitoring system may spend\ntime creating series or updating indexes, and a query can ask for a large set of\ncombinations. Increased pressure during an incident is particularly costly. An\nerror that includes a different exception message per request can cause a new\nseries for each failure at the time somebody most needs the aggregate signal.\n\nA dimension can still deserve its cost when it answers an important question. An\napplication might need to understand whether a request delay affects one of a\nfew supported regions. Budget the number of values, normalise their meaning and\nverify what happens to a value outside the expected set. That decision gives the\nmetric an intentional scope and a clear limit on the combinations it can\nproduce.\n\n## What it looks like in practice\n\nConsider a small API whose request metric records method, route template and\nstatus family. With five templates, two common methods and three observed status\nfamilies, there could be up to thirty combinations for those labels if every\ncombination occurred. Added dimensions such as a deployment environment or\nreplica can increase the total. Measure the actual distribution and the number\nof newly created series over a representative interval.\n\nTry a fixture that requests many distinct order URLs. The instrumentation should\nrecord their stable route template while retaining the method and outcome\ninformation that operators need. Inspect the labels the collector receives and\nthe latest data stored by the monitoring backend. A check at the source can miss\nvalues appended later by a shared adapter. Compare both sides before relying on\na limit.\n\nEngineer's\n[Grafana and Prometheus monitoring case study](/portfolio/cut-operational-risk-with-grafana-and-prometheus/)\ndescribes selecting meaningful measures and connecting alert thresholds with\noperations. The route example shows one way to keep such a measurement useful as\ntraffic grows. Preserve the grouping that lets an operator find an affected\nroute and provide a separate way to investigate an individual request when\nneeded.\n\nAlso review what happens on release. A deployment can create new instance labels\neven when routes and outcomes stay the same. Decide how long those old series\nremain relevant and how a query groups over current and previous instances. A\nfixture that repeats the same traffic through two application revisions can show\nwhether the change increases the number of combinations and changes an alert's\nmeaning.\n\n## Where it goes wrong\n\nA label can accidentally capture an unpredictable value while the code looks\nreasonable. An exception class might come from a small list, while its detailed\nmessage can contain filenames, identifiers or sensor positions. Choose stable\ncategories for aggregate measures and verify that the detail path follows the\napplication's privacy and retention policy. Excess detail in labels can create\nboth a cost and information exposure.\n\nLimits need testing as well. A system may combine excess attribute combinations\ninto an overflow series, refuse them or apply a different configured policy.\nVerify what happens when a test input exceeds the configured limit. A quiet\ndashboard can conceal that observations were dropped or grouped. Give operators\na way to detect an unexpected increase in cardinality before it erases the\ndistinctions they use during a failure.\n\nA capacity limit can apply to active series, series created per minute or\nallocated storage. Record which measure is constrained before tuning labels. A\nworkload with a moving process identifier may keep only a small number of active\nseries while creating many new ones over the retention period. Test a rolling\nreplacement and examine both counts. This shows whether a change improves the\nparticular resource the team wanted to protect.\n\nFinally, attach an owner and purpose to each label. Review series count, churn\nand query cost when a new dimension is proposed. Retain a small fixture covering\nknown routes and deliberately varied inputs. A useful metric lets the team ask\nconsistent questions about the workload without letting one new field make\ncollection or diagnosis unreliable.\n\n## Further reading\n\n- [Prometheus instrumentation guidance on labels](https://prometheus.io/docs/practices/instrumentation/#do-not-overuse-labels).\n  Discusses choosing dimensions and the cost of large combinations.\n- [OpenTelemetry SDK cardinality limits](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#cardinality-limits).\n  Describes limits and overflow handling.\n- [The Prometheus data model](https://prometheus.io/docs/concepts/data_model/).\n  Defines how names and labels identify time series.\n\n\u003chttps://engineer.company/glossary/cardinality/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"See how route templates, user IDs and time windows change the number and churn of active metric series.","formats":{"gemtext":"https://engineer.company/glossary/cardinality/index.gmi","gopher":"https://engineer.company/glossary/cardinality/gophermap","html":"https://engineer.company/glossary/cardinality/","json":"https://engineer.company/glossary/cardinality/index.json","markdown":"https://engineer.company/glossary/cardinality/index.md","pdf":"https://engineer.company/glossary/cardinality/index.pdf"},"kind":"page","language":"en","title":"What is metric cardinality?","url":"https://engineer.company/glossary/cardinality/","version":1}