Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

After a deploy, the Prometheus server runs out of memory because one service exports millions of time series. What is the likely cause and fix?

The likely cause is a metric tag with high cardinality: a tag whose values are unbounded, such as a user id, a full URL with ids in it, or an exception message. Each distinct value creates a new time series, so one careless tag on a custom Timer or Counter can create millions. The fix is to remove the tag or map its values to a small fixed set, protect the registry with a MeterFilter that denies or caps the tag, and put the detailed values in traces or logs instead.

Why this question is asked

This failure is common and expensive. It usually arrives with an innocent change: someone adds a tag to a counter to make a dashboard more detailed, and the next day the monitoring system is out of memory, dashboards for every team are blank and the vendor bill jumps. Interviewers ask it because the fix needs an understanding of how metrics are stored, not just of Spring Boot. In this answer, we will recap what a time series is and why tags multiply them, find the offending metric, look at the typical mistakes in Spring code, fix the code, add a safety net with MeterFilter, and decide where the detailed data should go instead.

1A Quick Recap of Time Series and Cardinality

Spring Boot records metrics with Micrometer. A meter, such as a Timer or a Counter, has a name and a set of tags, key-value labels like method=GET or status=200. Prometheus, which scrapes /actuator/prometheus from every pod, stores one time series for every distinct combination of metric name and tag values, and it keeps each active series in memory along with its recent samples.

Cardinality is the number of distinct values a tag can take. A status tag has maybe ten values. A method tag has a handful. Their combinations stay small. A userId tag has as many values as we have users. And the counts multiply: a timer with a histogram already produces around 30 bucket series per tag combination, so 100,000 users times 30 buckets times 40 pods is 120 million series. That is what pushes Prometheus out of memory.

How tags multiply series for one timer
Tags on the timerDistinct combinationsSeries with 30 buckets
method, status4 x 6 = 24720
+ uri template (40 routes)24 x 40 = 96028,800
+ userId (100,000 users)96,000,000about 2.9 billion
Bounded tags multiply into thousands; one unbounded tag multiplies into the billions.

2Finding the Offending Metric

Before changing code, we confirm which metric exploded. Prometheus can tell us which metric names have the most series, and its TSDB status page shows the labels with the most values. We can also look at one pod's output directly.

Properties
# PromQL: the ten metric names with the most series for the service
topk(10, count by (__name__) ({job="orders"}))
# payment_attempts_total 1843211
# http_client_requests_seconds_bucket 902340
# jvm_memory_used_bytes 48
# One pod's export size, before and after the deploy
curl -s http://orders-7f9c:8081/actuator/prometheus | wc -l
# 1.2 million lines (it was 4,000 before the deploy)

Notice that the two worst names point to two different mistakes: a custom counter and the HTTP client metrics. Both are classic, and both came in with the deploy.

3The Usual Mistakes in Spring Code

The first is a custom meter with a tag taken straight from request data.

Java
// Broken: one new series for every user and every distinct message
Counter.builder("payment.attempts")
.tag("userId", request.userId()) // 100,000+ values
.tag("error", e.getMessage()) // 'Card 4111... declined at 10:42:13'
.register(registry)
.increment();
// Broken: the URL is built by concatenation, so the client metric's uri tag
// is the real path with the id in it, not a template
restClient.get().uri("http://billing/invoices/" + invoiceId).retrieve().body(Invoice.class);
// uri="/invoices/88812", uri="/invoices/88813", ...

The error tag is as bad as the user id. Exception messages often contain ids, amounts and timestamps, so almost every message is unique.

The second mistake is subtler. Spring's HTTP client instrumentation tags client requests with the URI template when we give it one, such as uri("/invoices/{id}", invoiceId). When we concatenate the id into the string ourselves, the instrumentation only sees a finished URL and records it as is. The same happens on the server side if a filter or custom tag provider records request.getRequestURI() instead of the matched pattern.

4Fixing the Code

The fix is to keep only tags with a small, known set of values, and to map rich values to categories.

Java
// Fixed: bounded tags only
Counter.builder("payment.attempts")
.tag("outcome", "declined") // success, declined, error
.tag("reason", DeclineReason.of(e).name()) // INSUFFICIENT_FUNDS, EXPIRED, FRAUD, OTHER
.register(registry)
.increment();
// Fixed: pass a URI template so the uri tag is "/invoices/{id}"
restClient.get().uri("http://billing/invoices/{id}", invoiceId).retrieve().body(Invoice.class);

The reason tag now has five values at most, chosen by our code rather than by whatever text an exception carries. A useful rule of thumb for reviews is that every tag value should come from an enum, a route template or a small configuration list, never from user input or a free-text message.

5A Safety Net With MeterFilter

Code review will miss a tag eventually, so the application should protect the monitoring system itself. Micrometer's MeterFilter runs before a meter is registered and can drop a tag, deny a meter, or cap how many distinct values a tag may have. In Spring Boot, any MeterFilter bean is applied to the auto-configured registries.

Java
@Configuration
class MetricsGuards {
@Bean
MeterFilter dropUserTags() {
return MeterFilter.ignoreTags("userId", "sessionId", "email"); // tag removed, meter kept
}
@Bean
MeterFilter capClientUris() {
// after 100 distinct uri values, new http.client.requests meters are denied
return MeterFilter.maximumAllowableTags("http.client.requests", "uri", 100, MeterFilter.deny());
}
}
# Boot also caps uri tags with properties (names can vary by version)
management.metrics.web.client.max-uri-tags=100
management.metrics.web.server.max-uri-tags=100

Notice that the cap protects Prometheus but loses data for the denied meters, and Boot logs a warning when the limit is reached. That warning is a signal to fix the code, not a permanent solution. Check your Boot version for the exact property names, since the observation and metrics properties have moved between releases.

6Where the Detailed Data Belongs

The original author added userId for a real reason: someone wanted to know which user had failed payments. Metrics are the wrong tool for that question. Metrics answer how many and how fast, aggregated over bounded categories. Questions about one user, one order or one request belong in traces and logs, which are stored per event and indexed for search.

So the payment code increments the bounded counter, adds the user id and order id as attributes on the current trace span, and writes a structured log line with the same identifiers. A dashboard shows declines by reason; clicking through to traces or logs finds the individual users. Finally, after the fix, we delete the bad series from Prometheus or wait for them to age out, and add an alert on series count per job so the next explosion is caught within minutes.

7Follow-up questions

Why does high cardinality also hurt the application itself?

Micrometer keeps every registered meter in memory for the life of the application, and each scrape has to serialise all of them. A pod with a million meters spends a lot of heap and CPU on metrics, and the scrape itself may time out, which then looks like a missing target.

How would you catch this before it reaches production?

Count the lines of /actuator/prometheus in an integration test after exercising the main flows with many different ids, and fail the build if it grows beyond a budget. In production, alert when a job's series count grows by more than a set percentage after a deploy.

Is a high-cardinality tag ever acceptable?

Only when its values are bounded in practice and small, such as a tenant id in a system with 30 tenants. Even then, I would keep it off histograms and confirm the tenant count will not grow into the thousands.

8Conclusion

In this answer, we saw that every distinct tag combination is a separate time series, so a tag with unbounded values such as a user id, a concatenated URL or an exception message can create millions of series and exhaust Prometheus. We found the metric with a topk query, fixed the code by using bounded tags and URI templates, added MeterFilter rules and uri caps as a safety net, and moved per-user detail into traces and logs where it belongs.

What to say in the interviewAbout 80 seconds aloud

Open with

The most likely cause is a high-cardinality tag. Prometheus stores one time series per distinct combination of tag values, so a tag with unbounded values, like a user id, a full URL with ids in it or an exception message, creates a new series for almost every request, and histograms multiply that by the number of buckets.

Then, if they want more

First I would confirm it with a topk count by metric name in Prometheus, or by looking at the size of one pod's /actuator/prometheus output before and after the deploy.

Typical culprits are a custom Counter or Timer tagged with request data, or a RestClient call where the id is concatenated into the URL instead of passed as a URI template, so the uri tag holds the real path.

The fix is to remove that tag or map it to a small fixed set, such as an outcome and a reason enum, and to pass URI templates. As a safety net I would add MeterFilter beans that ignore tags like userId and cap the uri tag with maximumAllowableTags.

The per-user detail should go into trace attributes and structured logs instead, and I would add an alert on series count per service.

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
Spring Boot reference, Actuator
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 "After a deploy, the Prometheus server runs out of memory because one service exports...": https://scrivio-interview-library.netlify.app/spring-boot/actuator/a8e5e3aaa3/