CDN & Edge Caching

Explore how content delivery networks cache, serve, and invalidate content

Cache Hit vs Cache Miss

0
Cache Hits
0
Cache Misses
0%
Hit Ratio
-
Avg Hit Latency
-
Avg Miss Latency

Response Time Comparison

Cache HIT — served from edge
-
Cache MISS — fetched from origin
-

HTTP Cache Headers

# HTTP Response Headers
Cache-Control:public, max-age=3600
ETag:"abc123def456"
Last-Modified:Wed, 01 Jan 2025 00:00:00 GMT
Vary:Accept-Encoding, Accept-Language

max-age=N

The response can be cached and reused for N seconds without revalidation. After expiry, the browser must re-request.

s-maxage=N

Like max-age but only for shared caches (CDNs, proxies). Overrides max-age for CDN nodes. Browser still uses max-age.

public

Response can be cached by any cache — browser, CDN, proxy. Safe for static assets with versioned URLs.

private

Only the end-user's browser can cache this. CDN edges must not cache. Use for personalized responses.

no-store

Never cache this response anywhere. Every request goes to origin. Use for sensitive data like banking pages.

no-cache

Response can be stored but must be revalidated every time (via ETag/If-None-Match). Not the same as no-store!

must-revalidate

Once stale, must revalidate before use. Never serve stale content, even if origin is unreachable.

immutable

Content will never change during max-age. Browser won't make conditional requests. Use with content-hashed URLs.

Points of Presence (PoP) Network

A CDN deploys edge servers in dozens of global Points of Presence. When a user requests content, DNS routes them to the nearest PoP via Anycast or GeoDNS. The PoP serves cached content or fetches from origin and caches for future users in that region.

Cloudflare: 310+ PoPsAWS CloudFront: 450+ PoPsFastly: 90+ PoPs

Cache Invalidation

One of the two hardest problems in computer science. When content changes at origin, all edge caches must be notified.

Invalidation Strategies

Purge by URL

Send DELETE request to CDN API for specific URL. Propagates to all edges in 1-30 seconds. Guaranteed fresh content.

Cache-Busting URLs

Append content hash to filename: app.abc123.js. Old version stays cached. New version is fresh miss. Zero propagation delay.

Surrogate Keys

Tag responses with logical keys (e.g. product:123). Purge all tagged responses in one API call.

TTL Expiry

Content expires naturally after max-age. No action needed. Use short TTLs (60s) for mutable content, long (1yr) for immutable.