High Cardinality Metrics Are Breaking Your Monitoring Budget (And Your Database)
High-cardinality metrics create many distinct time series. If your monitoring memory usage, storage or query latency grows faster than the infrastructure you run, inspect the labels before adding capacity.
Labels such as user_id, request_id or a URL containing a customer identifier can add new series continuously. The useful question is which dimensions your alerts and dashboards actually require.
This guide explains how to find the largest sources of series growth, replace unbounded labels and check the result on a representative workload.
What High Cardinality Actually Costs
Every unique combination of labels creates a new time series. That sounds innocent until you do the math.
- Let's say you're tracking HTTP requests with these labels:
method(5 values: GET, POST, PUT, DELETE, PATCH)endpoint(100 unique API endpoints)status_code(20 common codes)user_id(10,000 active users)
The product 5 × 100 × 20 × 10,000 is 100 million possible label combinations. It is an upper bound for this example, not a prediction that every combination occurs. The actual count depends on which combinations your application emits, plus target labels and the metric type.
There is no universal RAM-per-series or monthly-cost multiplier. Measure your own active series, ingestion rate, memory, storage and query latency; scrape frequency, label lengths, series churn and retention also matter.
Check which metrics create the most series before changing the collection interval or retention. A short-lived identifier can generate many new series even when request volume is stable.
Find the Largest Sources in Prometheus
From a trusted administrative environment with access to your Prometheus instance, inspect its read-only TSDB status endpoint:
curl --fail --silent --show-error http://localhost:9090/api/v1/status/tsdbUse headStats.numSeries for the current head-series count, seriesCountByMetricName for large metrics and labelValueCountByLabelName for labels with many distinct values. These describe the current instance, not your entire billing history. Keep the endpoint private and use your normal authenticated access where required.
Compare these findings with the instrumentation source. Remove or normalize the unnecessary dimension at its origin, then verify collection, queries and alerts before expanding the change. Consult the TSDB status API and Prometheus instrumentation guidance.
Labels That Cause Unbounded Growth
Here's where most teams go wrong: they treat metrics like logs. They want to slice and dice by every possible dimension, so they add labels for everything.
- Examples of potentially unbounded labels:
request_id(unique per request)session_id(unique per session)file_path(thousands of unique files)sql_query(with parameter values baked in)customer_name(growing with each new customer)
Each of these can explode your cardinality. A request_id label makes every single request a unique time series. You're not monitoring patterns anymore. You're just creating an expensive, slow database of individual events.
Do not rely on memory pressure to discard only unwanted metrics. Resource exhaustion can interrupt collection or crash a process. Test a label change on one service before rolling it out.
The worst part? You probably don't need most of these dimensions for monitoring. You need them for debugging specific requests, but that's what logs are for.
Strategic Metric Design
Good metrics answer questions about system behavior, not individual events. Instead of tracking every user's clicks, track click rates by user type or region. Instead of monitoring every SQL query with its parameters, monitor query patterns by table or operation type.
Here's how to approach metric design:
- Set a finite vocabulary. Prefer a known route template, operation or deployment environment.
- Use the metric type for numeric observations. Record latency in a histogram instead of creating a label for each measured duration.
- Review new dimensions. Estimate their combinations and identify the alert or dashboard that needs them.
Question every label. Ask yourself: "Will I alert on this dimension? Will I dashboard it?" If you just want to filter by it occasionally, you don't need it as a metric label. Put it in logs instead.
Normalize dynamic values. Replace user IDs, request IDs, and timestamps in labels with stable categories. A user_type label (premium, free, admin) is infinitely more useful than individual user IDs for monitoring.
Use recording rules for repeated expensive queries. They save precomputed results as additional time series. They do not remove the original inputs or fix their ingestion cardinality. See the Prometheus recording-rule documentation.
For example, instead of this cardinality bomb:
http_requests_total{method="GET", endpoint="/api/users/12345", user_id="12345"}Consider this bounded alternative:
http_requests_total{method="GET", endpoint_group="user_api", user_tier="premium"}
Choose categories that preserve the operational question. For an HTTP route, a template such as /api/users/:id is usually more useful than a separate label value for each user URL.
Keep Request Detail Outside Metric Labels
Request-level details may belong in logs or traces rather than metric labels. Decide which detail you need to retain, how sensitive it is and what investigation it supports.
Sampling traces or logs can reduce the volume of those signals, but it does not automatically bound the labels on separately collected metrics. Do not assume that a trace-sampling setting fixes metric cardinality.
Retention controls how long data remains. It does not stop new label combinations from being generated. Per-metric retention or downsampling depends on your storage backend; verify the supported mechanism before designing around it.
If you need per-user analytics, use an analytics store designed for that question rather than adding every user identifier to operational metrics.
Measure the Result Before Expanding the Change
Record a baseline: active series, new-series rate, memory, disk growth, query latency and the billable unit used by your provider. Keep workload and collection settings comparable when checking the result.
Change one instrumentation source first. Verify that the intended alerts still work and that new series grow more slowly. Old stored series remain until the relevant retention or deletion mechanism removes them, so disk usage may not fall immediately.
The goal is to retain signals that lead to an action. A smaller set of well-chosen dimensions can be easier to investigate and operate than a detailed event history encoded as metrics.
Start with the question you want to answer, then design the minimum set of labels needed to answer it. Your infrastructure budget (and your on-call engineer) will thank you.
For managed host and service monitoring alongside your custom metrics, explore Fivenines Linux server monitoring. Fivenines does not automatically rewrite labels in an existing Prometheus installation. Our server monitoring guides cover CPU, memory, disk and related investigations.