A developer added `user_id` as a metric label. What is the problem and what do you advise?
BeginnerScenarioPrometheus and PromQL at Scale
Answer
Situation read → Unbounded label values create one time series per user. That is a cardinality explosion that raises memory, CPU and storage cost.
What I'd do →
- Remove the label from the metric.
- Use bounded labels only:
method,routetemplate (/users/:id, not/users/42),status_class. - For per-user analysis use logs or traces, which handle high cardinality, or use exemplars to link a metric to a trace ID.
- Add
label_limitandsample_limiton the scrape job and a CI review check on new metrics.
Why → Each unique label combination is a separate series. A million users times 10 routes is 10 million series.
Interview tip → Rule of thumb: metrics for aggregates, logs and traces for individuals.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYour EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?IntermediateYou run 3 Kubernetes clusters. Compare federation, remote_write and Thanos sidecar for a global view.Advanced