Quick revision
The short answer
The likely cause is high cardinality: because user id is a label, every combination of user, endpoint and region is a separate time series, so the series count grows with the number of users rather than with the size of the system. The fix is to remove unbounded labels such as user id from metrics and keep them in logs and traces, record latency as a histogram instead of every request, downsample old data with a retention period per resolution, and put a cardinality budget and series-growth alerts on every service.
What to remember
In this answer, we saw that a metrics system stores data as series, one per distinct label combination, so a user id label makes the series count grow with the user base and explains a tenfold jump in storage and query time. We moved user id into logs and traces, recorded latency as a histogram so cost is fixed per scrape, downsampled old data with retention per resolution, and added a cardinality budget with growth alerts so the problem cannot quietly return.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The likely cause is high cardinality: because user id is a label, every combination of user, endpoint and region is a separate time series, so the series count grows with the number of users rather than with the size of the system. The fix is to remove unbounded labels such as user id from metrics and keep them in logs and traces, record latency as a histogram instead of every request, downsample old data with a retention period per resolution, and put a cardinality budget and series-growth alerts on every service.
Why this question is asked
A tenfold growth in a month, without a tenfold growth in traffic, is the classic sign that something in the data model is multiplying rather than adding. This happens in real teams all the time: a developer adds a helpful label so they can debug one customer, and a few weeks later the metrics backend is out of memory and dashboards time out. Interviewers ask this scenario because it tests whether we understand how a metrics store counts data, which is in series, not in requests. In this answer, we will recap what a series is, calculate why a user id label explodes the count, look at the fix in the Java code, and then cover histograms, downsampling and the guardrails that stop it from happening again.
1A Quick Recap: Metrics Are Stored as Series
A metrics system such as Prometheus, VictoriaMetrics, InfluxDB or a TimescaleDB setup stores measurements grouped into series. A series is one metric name plus one exact set of label values. http_latency with endpoint = '/orders' and region = 'eu' is one series; the same metric with region = 'us' is a second one. Each series has its own entry in an index, its own buffer in memory for recent points, and its own stream of samples on disk.
This design is very efficient when the number of series is stable, because a new sample is just one more number appended to an existing series. It becomes very expensive when the number of series keeps growing, because each new series costs index space, memory and file overhead even if it only ever receives one sample. This is what we mean by cardinality: the number of distinct label combinations.
2Why a User Id Label Multiplies Everything
Let us put numbers on the scenario. Say the service has 60 endpoints and 4 regions, and 200,000 active users this month.
| Labels on http_latency | Distinct values | Series |
|---|---|---|
| endpoint | 60 | 60 |
| endpoint, region | 60 x 4 | 240 |
| endpoint, region, status | 60 x 4 x 5 | 1,200 |
| endpoint, region, user_id | 200,000 users, about 5 endpoints each | about 1,000,000 and rising |
So the label turned a few hundred series into a million or more. Notice that the growth follows users, not traffic. Every new user who signs up creates new series, which is why storage and query time can grow ten times in a month while request volume grows only a little. Queries suffer too: a dashboard that shows p99 latency per endpoint must now read and merge thousands of user-level series for each endpoint before it can compute anything.
There is a second multiplier hiding in the question: per-request latency. If the system stores every single request as a point, then the number of samples grows with traffic as well, and each high-cardinality series holds a sparse scatter of points that compress badly.
3Fix 1: Remove Unbounded Labels From Metrics
The first and most important change is in the code that records the metric. In a Spring Boot service using Micrometer, the broken version looks like this.
The user id has not disappeared; it has moved to the right place. Logs and distributed traces are built for high-cardinality detail, because they store individual events and are searched by id. If someone needs to know why user 12345 had a slow request, they search the logs or traces for that user, and the metric tells them which endpoint and region to look at. Many metric systems also support exemplars, which attach a trace id to a sample in a histogram bucket, so we can jump from a slow bucket on a dashboard straight to one example trace.
Notice also that endpoint must be the route template such as /orders/{id}, never the raw path. A raw path with ids inside is just another unbounded label in disguise.
4Fix 2: Histograms Instead of Every Request
The second change is how latency is recorded. Instead of storing each request's duration, a histogram counts how many requests fell into each latency bucket, for example under 10 ms, under 25 ms, under 50 ms and so on, plus a total count and sum. Each scrape interval stores one number per bucket, no matter whether the service handled ten requests or ten thousand.
So the storage cost becomes series times buckets times scrape intervals, which is fixed and predictable. Percentiles such as p95 and p99 are then computed at query time from the bucket counts, and they can be aggregated across instances, which is not true of percentiles that each instance computes on its own. With about 240 series and, say, 30 buckets, we store 7,200 numbers per scrape for this metric, compared with millions of points per minute before.
5Fix 3: Downsampling and Retention per Resolution
The third change is lifecycle. Raw scrapes at 15-second resolution are useful for a few days of debugging. After that, five-minute or one-hour resolution answers every question people actually ask. So we keep raw data for, say, 15 days, five-minute rollups for 90 days, and hourly rollups for two years. In TimescaleDB that means continuous aggregates with their own retention policies; in the Prometheus world it is usually done by a long-term store such as Thanos, Mimir or VictoriaMetrics, so check what your backend supports.
We should also clean up the damage already done. The million user-level series are still on disk, so after the code change ships we delete or let retention expire the old series, and we rebuild any dashboards that grouped by user.
6Guardrails: A Cardinality Budget and Growth Alerts
Fixing it once is not enough, because the next team will add the next helpful label. So we give each service a cardinality budget, for example 10,000 active series, and we enforce and watch it.
The Micrometer filter stops a runaway tag at the source, the alert catches growth within a day instead of a month, and the top-k query tells us which metric to look at first. Some backends also offer per-tenant series limits that reject new series beyond a quota, which is a hard stop that protects the shared system from one bad deploy.
7Follow-up questions
Is it ever acceptable to put a user id on a metric?
Only when the set of users is small and fixed, such as a handful of large enterprise tenants on a dashboard of per-tenant SLOs. Even then it is better to use a bounded tier label such as plan or tenant_tier, and keep per-user detail in logs, traces or an analytics store designed for it.
How is this different from a high-cardinality analytics database?
Columnar analytics stores such as ClickHouse treat user id as just another column and handle billions of distinct values fine, because they do not keep an index entry and buffer per series. If the business really needs latency per user, recording request events into such a store is the right tool, not a metrics backend.
Why not just add more memory to the metrics server?
Because the growth is unbounded. More memory buys a few weeks until the user base grows again, while query times keep rising because every aggregation reads more series. Fixing the data model is the only change that makes cost proportional to the system rather than to the customer count.
8Conclusion
In this answer, we saw that a metrics system stores data as series, one per distinct label combination, so a user id label makes the series count grow with the user base and explains a tenfold jump in storage and query time. We moved user id into logs and traces, recorded latency as a histogram so cost is fixed per scrape, downsampled old data with retention per resolution, and added a cardinality budget with growth alerts so the problem cannot quietly return.
Open with
My first suspicion with a tenfold growth in a month is cardinality, not traffic. Metrics backends store data per series, and a series is one metric name plus one exact set of label values.
Then, if they want more
Endpoint and region are bounded, maybe 60 times 4 gives 240 series, but user id is unbounded, so every user and endpoint and region combination becomes its own series and the count grows with the user base. That costs index memory, disk and query time, because a per-endpoint dashboard now has to merge thousands of user series.
I would confirm it by looking at the series count per metric and per label. The fix is to remove user id from the metric; that detail belongs in logs and traces, ideally linked with exemplars. I would also check that endpoint is the route template, not the raw path.
Then I would record latency as a histogram instead of individual requests, so storage is series times buckets per scrape and percentiles can be aggregated across instances. For history I would downsample, keeping raw data for a couple of weeks and rollups for longer.
Finally I would add guardrails: a series budget per service, a Micrometer filter that caps tag values, and an alert on daily series growth.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation, MongoDB manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A metrics system stores per-request latency with labels for user id, endpoint and...": https://scrivio-interview-library.netlify.app/databases/nosql-fundamentals/4d5215e6c3/