CDNs: edge hits and origin protection
Trace edge and shield misses, design safe cache keys, choose freshness controls, and calculate how much traffic reaches the origin.
20 min7 steps
By the end you can
- Trace cache hits and misses through edge, shield and origin
- Choose cache keys and TTLs that preserve representation boundaries
- Choose versioned URLs or invalidation for a content update
- Calculate request hit ratio and origin offload with and without a shield
Serve close to the reader
An edge cache serves reusable responses near readers. A hit avoids the origin round trip. A miss still needs an upstream fetch, so proximity alone does not guarantee fast responses or origin protection.
Separate representations, not tracking noise
Include when content varies
- Path and required query fields
- Language or image format
Exclude only when irrelevant
- Tracking parameters
- Unneeded request headers
A cache key identifies a representation. Omitting a meaningful input mixes responses; including irrelevant inputs fragments hits. Respect Vary and the CDN policy. Private or personalized responses generally bypass shared caching; adding a user identifier alone is not a complete privacy policy.
Set an explicit reuse window
t0
Edge stores version A
t10
Origin publishes version B
t59
Edge may still serve fresh version A
t60
Entry becomes stale; validate or refetch
TTL controls freshness, not physical deletion. s-maxage targets shared caches; max-age also affects browser caches. Once stale, a response may be revalidated rather than fully downloaded. Stale-serving directives can extend reuse, so TTL alone is not an unconditional end-to-end staleness guarantee.
Gather misses before the origin
An origin shield adds a shared cache tier between edges and origin. Repeated edge misses can become shield hits. It adds a hop on a shield miss and another operational dependency. Simultaneous cold misses need request coalescing to avoid duplicate origin fetches.
Publish safely under an old URL
Versioned immutable asset
- New content gets new URL
- Update references to new version
Invalidate existing URL
- Evict matching shared entries
- Allow propagation; browser copies may remain
Versioned URLs keep immutable assets reusable while new references select new content. Purges remove cached entries for an existing URL, with provider-specific scope and delay. CDN invalidation does not erase browser copies. Neither method prevents a post-purge surge of misses without origin capacity or coalescing.
Count misses through both tiers
- Arrive at edges10,000 requests/s
- Reach shield1,000 requests/s
- Reach origin200 requests/s
Origin rate = incoming rate ? (1 ? edge hit ratio) ? (1 ? shield hit ratio on edge misses). Here 10,000 ? 0.1 ? 0.2 = 200 requests/s: 98% request offload. Byte offload can differ when misses are larger than hits.
Do not confuse hits with saved bytes
- Bytes served from cache9 KB
- Bytes fetched from origin1,000 KB
Request hit ratio counts requests. Byte hit ratio weights response sizes. Nine tiny hits and one huge miss give 90% request hits but only 9 / 1,009 ? 0.9% byte hits. Track both when origin bandwidth is the bottleneck.
Loading question…
Mastery check
5 questions on fresh variants. One attempt each, no time limit. Score 80% or more to master the lesson.
Answer this step to continue.