Lesson 7 of 13 · 13m
A Label Is a Database Row
Every unique labelset mints a series held in RAM, and http.route is the fix for path-shaped cardinality explosions.
In Prometheus, a label is not a tag on a metric. A metric name plus the complete set of label name/value pairs is the series — a row in the TSDB's Head block, held in RAM, indexed by postings lists. http_requests_total{path="/users/8471", status="200"} and http_requests_total{path="/users/8472", status="200"} are two different series, two allocations, two index entries. Every new label value combination mints a new series whether or not anything ever queries it.
This is the bill that arrives labeled "cardinality," and it multiplies, it doesn't add. Fifty pods × forty routes × five status classes = 10,000 series for one metric. Add a le dimension — a histogram with twelve buckets — and each labelset costs twelve bucket series plus _sum and _count, so that "one metric" is really fourteen series per labelset. The day someone ships user_id or a raw path as a label, the Head block starts minting a series per request, ingestion churn climbs, GC pressure climbs with it, and the server's memory curve looks like a launch trajectory. prometheus_tsdb_head_series is the metric that tells you you did this; scrape_samples_scraped shows the sample volume per scrape and scrape_series_added shows how much of it was brand-new — the churn detector, since a steady service should mint near-zero new series after warm-up.
"Labels are tags" is the wrong model
Tags imply an unconstrained set you filter on. Prometheus labels are dimensional axes — every axis's cardinality multiplies the storage. Grafana Labs' own cardinality postmortems name this the leading cause of Prometheus OOMs and crashloops, and every hosted backend (Mimir, Cortex, M3DB) enforces per-tenant series limits that reject your writes with 400s once you cross them. The failure mode isn't slow queries; it's the TSDB eating its RAM or your remote-write queue silently dropping.
Where unbounded values come from
Instrumentation defaults. An HTTP auto-instrumentor that uses the request path puts /users/8471 — or worse, /reset-password?token=..., which also leaks secrets into your metrics — into a label. This is why OpenTelemetry's semantic conventions separate http.route (the template, /users/:id, bounded by your route table) from url.path (unbounded, an attribute, never a Prometheus label). http.target existed in older semconv versions and carried path+query — if your instrumentation predates the split, that label is the same trap under an old name. If your metrics contain raw paths, your instrumentation is emitting a series mint, not a metric.
The fixes are concrete
Bound values at instrumentation: use http.route, collapse ID-shaped segments, cap the distinct values any label can take. Drop what you don't need at scrape time with metric_relabel_configs — action: drop for whole metrics, labeldrop/labelkeep for axes — before remote write amplifies them. A metric_relabel_configs entry like {action: labeldrop, regex: "(net|app)_.*"} strips the infra-label namespaces exporters pile on when you don't need them. sample_limit, target_limit, and label_limit per scrape_config bound what a single target can emit. On the backend side, Mimir/Cortex's max_global_series_per_user and per-metric limits exist so one team's session_id label can't take down the tenant.
Practice
- Every label value must be bounded by something you can enumerate: routes, status classes, regions. If you can't list the possible values, it isn't a label.
- Track
prometheus_tsdb_head_seriesper job and set a cardinality budget per metric — under ~10k series is a sane ceiling for a single instrumentation metric. - Histograms multiply by bucket count; choose buckets deliberately (next lesson) and never add a label axis to a histogram casually.
- Drop before remote write: relabeled-away series never leave your RAM, and that's the cheapest place to kill them.
Cardinality isn't a scaling problem that arrives at millions of requests. It's a schema decision that arrives at the first path label.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.