Stage 4 · Provision
Cache Design Patterns
Cache Observability
Hit ratio, eviction rate, latency, object size, and origin offload metrics for cache tiers.
Why Cache Observability?
Caches are invisible when they work and catastrophic when they fail. Cache observability provides visibility into cache health, effectiveness, and impact on downstream systems. Without it, you cannot optimize cache performance or detect cache failures.
Hit Ratio
Hit ratio is the percentage of requests served from cache. A high hit ratio (90%+) means the cache is effective. A low hit ratio means the cache is not capturing the right data or the TTL is too short.
# Hit ratio
sum(rate(redis_keyspace_hits_total[5m]))
/
(sum(rate(redis_keyspace_hits_total[5m])) + sum(rate(redis_keyspace_misses_total[5m])))
# Redis INFO stats
# hit_rate = keyspace_hits / (keyspace_hits + keyspace_misses)
# Target: > 90% hit rate
# Alert: hit_rate < 0.8 for 5 minutesHit ratio is the most important cache metric. A drop in hit ratio means more requests hitting the database, which increases latency and load.
Eviction Metrics
- Evicted keys — Keys removed due to memory pressure. High eviction = cache too small.
- Memory usage — Current memory used vs maxmemory. High usage = nearing eviction.
- Eviction rate — Keys evicted per second. Increasing rate = growing working set.
- TTL distribution — How many keys are near expiry. Clustered TTLs cause mass eviction.
Latency Metrics
# Redis command latency (using redis_exporter)
redis_command_duration_seconds_count{cmd="get"}
# p99 latency target: < 1ms
histogram_quantile(0.99, rate(redis_command_duration_seconds_bucket[5m]))
# Alert: p99 > 2ms for 5 minutesCache latency should be sub-millisecond. If latency increases, check for network issues, large values, or Redis memory pressure.
Origin Offload
Origin offload measures how much traffic the cache prevents from reaching the database. A 90% hit ratio means 90% of requests are served from cache, and only 10% reach the database. This is the ultimate measure of cache effectiveness.
Total requests: 100,000/min
Cache hits: 95,000/min
Cache misses: 5,000/min
Origin offload: 95,000 / 100,000 = 95%
Database QPS: 5,000 / 60 = 83 QPS (instead of 1,667 QPS)
Without cache: 1,667 QPS to database
With cache: 83 QPS to database
Reduction: 95%Origin offload directly translates to database load reduction. Every percentage point of hit ratio improvement reduces database load proportionally.
Cache Dashboards
- Hit ratio over time — Is the hit rate stable, improving, or degrading?
- Eviction rate — Are keys being evicted faster than expected?
- Memory utilization — How close to the memory limit?
- Latency percentiles — Is cache latency within SLA?
- Top keys by QPS — Which keys are hottest?
- Origin QPS — How much traffic reaches the database?
Break down hit ratio by key prefix (product:, user:, session:). This reveals which cache namespaces are underperforming. A low hit ratio on product: may indicate a TTL that is too short.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.