Skip to content
shiporbreak

No streak yet

Sign in

November 28, 2026 路 #73

CloudMediumOpen write-up

A million time series from one label

After a launch, Prometheus runs out of memory and the monitoring bill triples. Which line is the cause?

from prometheus_client import Counter

REQUESTS = Counter(
    "http_requests_total", "HTTP requests",
    ["method", "route", "status", "user_id"],
)

def handle(req, resp):
    REQUESTS.labels(
        req.method, req.route, resp.status, req.user_id
    ).inc()

Next puzzle in UTC

One try. The first answer sticks.

How to fix it

Prometheus stores one time series per unique label combination. An unbounded label like user_id multiplies all the others and grows memory and storage without limit. Drop it from the metric.

In Prometheus, a metric name plus a unique set of label values is one time series. The number of series is roughly the product of the distinct values for each label. method, route, and status are small, fixed sets. user_id grows with your user base, so 100,000 active users multiply every other combination by 100,000. This is called high cardinality, and it drives up memory in the server, query latency, and the bill with hosted backends.

Fix

REQUESTS = Counter(
    "http_requests_total", "HTTP requests",
    ["method", "route", "status"],
)

Keep labels to bounded values, and use the route template (/users/{id}) instead of the raw path. Put per-user detail where high cardinality belongs: structured logs, or trace attributes in OpenTelemetry. If you need to know which customers are affected, query logs by user_id, and keep metrics for aggregates and alerting. Check your worst offenders with topk(10, count by (__name__)({__name__=~".+"})).

Sponsor this spot

Put your tool on the puzzle
One labeled card, in front of engineers who show up every day from YouTube, TikTok, and Instagram.