What is a recording rule, and when would you use one? [Basic]
Answer
A recording rule precomputes and stores the result of a PromQL expression as a new time series. I use recording rules for expensive, frequently used, or standardized queries such as service:error_ratio:rate5m.
Technical explanation
Recording rules improve dashboard performance and make alert expressions simpler and more consistent.
They are evaluated on a schedule by Prometheus and stored like normal metrics.
Naming should be consistent and indicate level, metric, operation, and window.
Hands-on example
Example rule:
groups:
- name: service-slo
rules:
- record: service:http_error_ratio:rate5m
expr: sum(rate(http_requests_total{status=~'5..'}[5m])) by (service) / sum(rate(http_requests_total[5m])) by (service)Then alerts and dashboards reuse service:http_error_ratio:rate5m.
Preparing for an interview?
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
- What is an alerting rule, and how does it differ from a recording rule? [Basic]
- How do you compute a 95th percentile latency from a histogram in PromQL (histogram_quantile)? [Basic]
- What is the difference between rate() and irate()? [Basic]
- What is PromQL, and what is an instant vector versus a range vector? [Basic]
- How does Prometheus handle high cardinality, and why is it a problem? [Intermediate]
- What is the Pushgateway, and why is it discouraged for most cases? [Basic]
- What is the difference between an exporter and instrumenting your app directly? [Basic]
- How does Prometheus storage (TSDB) work, and what is the retention model? [Intermediate]