awesome-everything RU
↑ Back to the climb

Caching

Cache layers: header and trace reading

Crux Read real Cache-Control headers, response trace headers, and a layered hit/miss path, then pick the behaviour and the highest-leverage fix.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

Cache bugs are diagnosed in the response headers and the per-layer trace, not in a diagram. Read the header, predict what each layer does, and choose the fix a senior makes first.

Goal

Practise the loop you run on every cache incident: read the Cache-Control directives and the trace headers, follow the request down the layer stack, and find which layer is lying before you touch a TTL.

Snippet 1 — the response header

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, no-store
Quiz

An engineer adds this header to a personalized /me endpoint, then asks why the CDN hit ratio is 0% and origin load did not drop. What is correct?

Snippet 2 — the trace headers

HTTP/1.1 200 OK
Age: 240
Cache-Control: public, max-age=300
CF-Cache-Status: HIT
X-Cache: MISS from reverse-proxy
Quiz

A user reports stale data 4 minutes after a write. Reading these headers from the same response, what do you conclude?

Snippet 3 — the layered hit/miss path

client → CDN edge → reverse proxy → app (Redis) → Postgres
         miss        miss            HIT (Redis)   —
Quiz

A request misses the CDN and the reverse proxy but hits Redis at the app layer. For an in-region setup, what is the rough latency story, and what does it tell you?

Snippet 4 — stale-while-revalidate

Cache-Control: public, max-age=60, stale-while-revalidate=600
Quiz

A high-traffic, slightly-stale-tolerant feed switches to this directive and p99 drops sharply with no rise in origin load spikes. Why does it work?

Recap

Cache behaviour is read in headers and traces. Cache-Control directives decide which layers may store a response — no-store forbids all, private forbids shared caches like the CDN — so a personalized endpoint correctly shows a 0% CDN hit ratio. Per-layer trace headers (CF-Cache-Status, X-Cache, Age) let you walk the stack and find which copy is stale: a CDN HIT within max-age that survived a write means the CDN was not purged. A hit deep in the stack means every layer above it added a miss hop, so confirm each layer earns its place. And stale-while-revalidate serves a stale copy instantly while refreshing in the background, cutting p99 and smoothing origin load for staleness-tolerant reads.

Continue the climb ↑Cache layers: place the cache where it earns its place
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.