awesome-everything RU
↑ Back to the climb

Networking & Protocols

CDN and edge: header and trace reading

Crux Read real response headers, a Cache-Control line, an edge-worker handler, and a CDN trace, then pick the behaviour or the highest-leverage fix.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

CDN problems are diagnosed in response headers, Cache-Control lines, and edge logs — not in prose. Read each artefact, predict what the cache and the worker actually do, then choose the fix a senior engineer reaches for first.

Goal

Practise the loop you run in every CDN incident: read the headers and the trace, predict cacheability and hit rate, and pick the highest-leverage change before touching routing or origin.

Snippet 1 — the response headers

HTTP/2 200
cache-control: public, max-age=3600
vary: User-Agent, Accept-Encoding, Cookie
cf-cache-status: MISS
age: 0
Quiz

Hit rate on this cacheable HTML sits near 5%. Reading only these headers, what is the dominant problem and the fix?

Snippet 2 — the Cache-Control line

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

A product-listing endpoint sends this. Describe what the shared CDN cache does at second 0, second 120, and during an 8-minute origin outage at second 300.

Snippet 3 — the edge worker

export default {
  async fetch(req, env) {
    const page = await fetch(req);                 // cacheable chrome + body
    const price = await fetch(env.PRICING_URL);    // per-user, never cached
    return new HTMLRewriter()
      .on("#price", { element(e) { e.setInnerContent(price.statusText); } })
      .transform(page);
  },
};
Quiz

This edge-side composition worker is correct in shape but has a latency bug on the critical path. What is it, and what is the fix?

Snippet 4 — the CDN trace

$ curl -sI https://example.com/article/42 | grep -iE 'cache|age|via'
cf-cache-status: HIT
age: 7200
cache-control: public, max-age=86400
Quiz

You deployed a corrected version of /article/42 ten minutes ago, but users still see the old text. Reading this trace, why, and what is the fastest correct fix?

Recap

Every CDN incident is read in headers and traces: a Vary header listing User-Agent or Cookie fragments the cache key per request and collapses hit rate; max-age plus stale-while-revalidate and stale-if-error define a freshness window, a stampede-safe stale window, and an outage fallback; an edge composition worker must parallelise its fetches and bound the volatile one with a timeout and fallback; and a HIT with age below max-age means a stale deploy that only a purge will clear. Diagnose from the artefact, apply the highest-leverage fix, then re-check the same header to confirm.

Continue the climb ↑CDN and edge: build and tune an edge delivery layer
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.