What causes a cardinality explosion, and how do you prevent it? [Intermediate]
Answer
A cardinality explosion happens when a metric label has many or unbounded values, or when multiple labels multiply together unexpectedly. It is prevented by limiting labels to stable, bounded dimensions and reviewing instrumentation before release.
Technical explanation
Common causes are raw URL paths with IDs, customer IDs, pod UIDs, exception messages, dynamic queue names, and per-request labels.
Use templated routes like /orders/{id} instead of /orders/12345.
Apply metric relabeling carefully, but fixing instrumentation at source is the best solution.
Hands-on example
Example: replace http_requests_total{path='/users/123/orders/456'} with http_requests_total{route='/users/{user_id}/orders/{order_id}', method='GET', status='200'}. For user-level debugging, use logs or traces, not metric labels.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Observability interview questions
- How does Prometheus handle high cardinality, and why is it a problem? [Intermediate]
- How does Prometheus storage (TSDB) work, and what is the retention model? [Intermediate]
- What is the difference between Thanos and Cortex/Mimir at a high level? [Intermediate]
- What is an alerting rule, and how does it differ from a recording rule? [Basic]
- How does Prometheus integrate with Kubernetes service discovery? [Intermediate]
- What is a recording rule, and when would you use one? [Basic]
- What is the Prometheus Operator, and what are ServiceMonitor and PodMonitor? [Intermediate]
- How do you compute a 95th percentile latency from a histogram in PromQL (histogram_quantile)? [Basic]