Course contentsShow
← Software Engineering
Lesson 1145 of 1,93334. Logging and ObservabilityFree lesson

Recording Rules and Precomputation

Speeding up expensive queries by precomputing and storing derived metrics at regular intervals.

Recording Rules and Precomputation

What you'll learn: How to speed up expensive metric queries by precomputing and storing results at regular intervals.

When you query complex metrics—like the 99th percentile latency across 50 services over the past hour—the calculation can take seconds or even time out. This hurts dashboard performance and alerting speed. Recording rules solve this by computing these expensive queries ahead of time and storing the results as new, simpler metrics.

How It Works

Think of it like a restaurant prep station. Instead of chopping vegetables to order (slow), the chef precompares common ingredients during off-hours and stores them ready to use (fast). Recording rules work the same way: they run your complex aggregations periodically (say, every minute) and save the results as new time series.

For example, if you frequently need to know the average request rate per service across hundreds of instances, a recording rule might compute this every 60 seconds and store it. Your dashboards then query this precomputed metric instead of recalculating from raw data every time.

When to Use Recording Rules

Use recording rules when:

  • Dashboard queries are slow or timing out
  • You repeatedly calculate the same complex aggregation
  • You need to query data across large label cardinalities
  • Alert rules need sub-second evaluation times

The trade-off: you use more storage (new metrics) and see slightly delayed data (refreshed at rule intervals), but gain dramatically faster query performance.

Key Takeaway: Recording rules precompute expensive metric calculations at regular intervals, transforming slow queries into fast lookups at the cost of increased storage and minor staleness—essential for high-performance dashboards and alerting.