Question presented to candidate: "Our news site sits behind Cloudflare, but the dashboard shows a cache hit rate around 30% and the origin is struggling. Editors also complain that when they fix a headline, readers keep seeing the old one. How would you get the hit rate above 95% without serving stale articles?"
What a strong answer should cover:
- Why the hit rate is low out of the box: Cloudflare caches by file extension and does not cache HTML or JSON by default;
Set-Cookie,privateorno-storeresponses are not cached; tracking query strings split one page into thousands of cache keys - The core move: cache HTML with a long edge TTL and make freshness event-driven by purging by tag (
Cache-Tagheader) when content changes, instead of relying on short TTLs - Cache key normalisation: ignore or strip
utm_*,fbclid,gclid; sort query strings; never vary on cookies for public pages - Separate edge TTL from browser TTL (
CDN-Cache-Control/Cloudflare-CDN-Cache-Control, or Cache Rules), so purges reach users - Origin protection: Tiered Cache (an upper-tier PoP between edges and origin), stale-while-revalidate, and Cache Reserve for the long tail
- Measuring it:
cf-cache-status, hit rate by path, and origin offload rather than a single number
Clarifying questions expected:
- Which responses are personalised (logged-in pages, paywall), and which are the same for everyone?
- How quickly must an edit be visible, and does the CMS emit an event on publish?
- Which Cloudflare plan, since some cache-key controls are Enterprise-only?
Code / implementation expected: Optional — the response headers, a Cache Rule outline and a purge call on publish; the example simulates a day of traffic under each strategy.