Skip to main content
In this hands‑on lesson you’ll see how a single unbounded label can explode the number of Prometheus time series, how to measure that effect, and how to fix it using metric relabeling at scrape time. We’ll:
  • Deploy two versions of a shopping cart API (low- and high-cardinality).
  • Generate traffic against both.
  • Inspect the scraped metrics and compare time series counts.
  • Apply Prometheus metric relabeling via a ServiceMonitor to drop the problematic label.
  • Verify the reduction in stored series in Grafana Explore.

Overview

Cardinality multiplies across label dimensions. For example:
  • method: 5 values
  • endpoint: 50 values
  • status: 10 values
  • user_id: 1,000,000 values
Multiply those and you get billions of distinct time series. A single high-cardinality label (like user_id) can overwhelm your storage and RAM.

1) Deploy the low-cardinality application and generate traffic

Apply the ServiceMonitor and other manifests for the low-cardinality app, and confirm the pod starts:
Start the traffic generator for the low-cardinality API in the background:
After ~45 seconds, stop traffic generation and capture the metrics endpoint:
Count histogram bucket lines for the cart_order_duration_seconds metric:
This low-cardinality deployment exposes route templates (e.g., /cart/user/{user_id}) rather than emitting a distinct user_id value per request, so the number of series is bounded.

2) Inspect a sample of the low-cardinality metrics

Below is a short excerpt from the scraped metrics (kept as raw text to avoid MDX parsing):
Key points:
  • The endpoint label uses a route template (/cart/user/{user_id}), not the concrete user_id.
  • Labels present: endpoint, le, method, status — none are unbounded per-user labels.

3) Deploy the high-cardinality application and generate traffic

Apply the high-cardinality manifests and verify the pod:
Start the high-cardinality traffic generator:
After ~45 seconds, stop the generator and capture metrics:
Count bucket lines:
Compare: low-cardinality had 28 lines vs high-cardinality with 2,114 lines — roughly a 100× increase caused by exporting a per-user label.

4) Inspect the high-cardinality metric lines

A sample of the high-cardinality output shows a concrete user_id label being exported:
That concrete user_id label is the unbounded dimension responsible for multiplying the number of distinct time series.

5) Why this is a problem

  • Each unique combination of label values is stored as a separate time series.
  • An effectively unbounded label (user IDs, IPs, UUIDs, pod names) multiplies cardinality and RAM consumption.
  • Rule of thumb: each series consumes on the order of kilobytes. Millions or billions of series means terabytes of RAM.
Best practices:
If you cannot change the application (legacy or third-party), use Prometheus metric relabeling at scrape time to drop or rewrite problematic labels so high-cardinality data is never stored.

6) Use metric relabeling to drop the high-cardinality label

Prometheus supports metric_relabel_configs and the Prometheus Operator’s ServiceMonitor CRD exposes metricRelabelings under each endpoints entry. Apply relabeling so the user_id label is removed during scrape and never written to the TSDB. Here is the ServiceMonitor snippet that includes the metricRelabelings section (the original manifest showed this as commented lines). Keep metricRelabelings under the endpoints stanza:
Uncomment those lines in high-cardinality-app/k8s/servicemonitor.yaml, then reapply:
Regenerate traffic and allow Prometheus to scrape the target. The relabeling will drop user_id before Prometheus stores the samples.

7) Verify the effect in Grafana Explore

Log in to Grafana (example credentials: admin / admin), open Explore, and run:
You should observe the series count drop from roughly 2,000 to 28 — matching the low-cardinality deployment. This confirms that relabeling removed the user_id dimension at scrape time, reducing stored series while preserving aggregated metrics.
A screenshot of a web page prompting to update your password with fields for new and confirm password and a Submit button. A browser password-save popup overlays the page, showing the username "admin" and a masked password.
Example Grafana Explore query and expected result:

8) Final takeaway

  • Prometheus scrapes whatever metrics an application exposes.
  • Metric relabeling (via metric_relabel_configs or metricRelabelings in a ServiceMonitor) runs at scrape time and can drop or modify labels before samples are written to the TSDB.
  • Dropping unbounded labels (for example user_id) prevents cardinality explosions and dramatically reduces Prometheus storage and RAM usage — without modifying the application.
Do not rely on metrics to hold high-cardinality, per-entity data. Use logs, traces, or a dedicated datastore for per-request diagnostic data. Reserve metrics for aggregated and bounded observability signals.

Watch Video