Back to roadmap
Module 4 · Edge: DNS, CDN, Load BalancersDay 03225 min

CDN Caching and Invalidation

Cache headers are a contract; invalidation is its escape hatch.

Day 032

CDN Caching and Invalidation

Fresh
note
Stale
note
Revalidate
service
Origin
service
Signal path
Cache lifecycle: hit, miss, stale-revalidate
Fresh
note
flow
Stale
note
Stale
note
flow
Revalidate
service
Revalidate
service
if needed
Origin
service
Memory hook

CDN Caching and Invalidation: cache headers are a contract

Mental model

move the first decision closer to the user

Design lens

Renames need build pipeline support.

Recall anchors
HeadersInvalidate

Why it matters

CDN behavior is controlled by HTTP cache headers and tag/path-based invalidation APIs. The two strongest patterns are versioned URLs (immutable cache) and stale-while-revalidate (soft refresh).

Deep dive

Cache-Control: public, max-age=N for shared caches.

stale-while-revalidate: serve stale immediately, refresh in background.

stale-if-error: serve stale on origin failure — cheap availability.

Invalidate by URL purge for surgical fixes; version bumps for global cache busts.

Demo / scenario

Marketing changed homepage hero image.

  1. Image had Cache-Control: max-age=86400.
  2. Purge URL via CDN API.
  3. Or: rename file with hash and update HTML reference.
  4. Renames are bullet-proof; purges are faster but eventual.

Tradeoffs

  • Renames need build pipeline support.
  • Purges propagate over seconds to minutes.
  • Tag-based invalidation (Surrogate-Key) is the cleanest at scale.

Diagram

if needed
Fresh
Stale
Revalidate
Origin
Cache lifecycle: hit, miss, stale-revalidate.

Mind map

Check yourself

Loading quiz…

Sources & further reading