- 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 valuesendpoint: 50 valuesstatus: 10 valuesuser_id: 1,000,000 values
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:cart_order_duration_seconds metric:
/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):- The
endpointlabel uses a route template (/cart/user/{user_id}), not the concreteuser_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:4) Inspect the high-cardinality metric lines
A sample of the high-cardinality output shows a concreteuser_id label being exported:
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.
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 supportsmetric_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:
high-cardinality-app/k8s/servicemonitor.yaml, then reapply:
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:
user_id dimension at scrape time, reducing stored series while preserving aggregated metrics.

8) Final takeaway
- Prometheus scrapes whatever metrics an application exposes.
- Metric relabeling (via
metric_relabel_configsormetricRelabelingsin 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.
Links and references
- Prometheus metric relabeling and
metric_relabel_configs: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs - Prometheus Operator ServiceMonitor API: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor
- Grafana Explore documentation: https://grafana.com/docs/grafana/latest/explore/