Skip to content

DNS / HTTP · 4 of 8

Step 1 · The pattern

Hits never reach you

The edge keeps a copy of each page. A request for a page it already holds is a hit: served from the edge, and your origin never sees it. Most traffic ends here.

  • hit, served at the edge
  • miss → origin

In short

CDN hit/miss: how it works and how it breaks

A CDN keeps copies of your responses on servers near users. When a request arrives, the edge looks for a stored copy: a hit is served at once, a miss is fetched from your origin, stored, and then served. What counts as 'the same request' is decided by the cache key, which by default is the full URL including its query string. That default is fragile. Add a tracking parameter with a different value per visitor, such as a click ID, and every URL is unique. Each request misses, is stored under a key nobody will ask for again, and the origin takes the full traffic it was sized to see only a sliver of. The hit rate drops from ninety-odd percent to almost nothing without any deploy. The fix is to control the key: strip or ignore parameters that do not change the response.

How this comes up in interviews

"A marketing campaign launches and your origin is suddenly overloaded, although no code was deployed and the pages are cacheable. What do you check?"

Then they ask

  1. How do you decide which query parameters belong in the cache key?
  2. What goes wrong if you strip a parameter that does change the response?
  3. How would you protect the origin if the hit rate collapsed again for a different reason?

A strong answer covers

  • A hit is served from the edge and never reaches the origin. A miss is fetched, stored, then served.
  • The cache key decides what counts as the same request. By default it is the full URL with its query string.
  • A per-visitor tracking parameter makes every URL unique, so nothing is ever a hit and the origin gets everything.
  • Control the key: strip or ignore parameters that do not change the response.
  • Keep a parameter such as a page number in the key, because it changes what the server returns.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last updated: Standard

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.