CDN: what it is and how it caches your content at the edge
CDN architecture, edge nodes, PoP, origin pull, cache HIT and MISS, CDN headers X-Cache, Vary header, cache key, geographic latency reduction
How CDNs Cache Content
A CDN (Content Delivery Network) is a globally distributed network of edge servers that cache your content close to users. Instead of every user hitting your origin server in one data center, they hit a nearby edge node โ reducing latency from 200ms to 20ms.
How it works
The CDN operates on pull caching. The first request to an edge node results in a cache MISS: the edge fetches the response from your origin and stores it. Subsequent requests from users near that edge result in cache HITs โ served directly from the edge without touching your origin.
# CDN adds diagnostic headers
CF-Cache-Status: HIT # Cloudflare: served from edge cache
X-Cache: Hit from cloudfront # CloudFront: cache hit
Age: 3412 # Seconds since entry was cached at edgeThe Vary header
Vary: Accept-Encoding tells the CDN to store separate cache entries for different encodings (gzip vs brotli). Vary: Accept-Language stores one per language. Be careful โ Vary: Cookie effectively disables CDN caching (every unique cookie = unique cache key).
Cache key
By default the cache key is the URL. CDNs can be configured to include or exclude query parameters and headers from the key. Strip irrelevant tracking parameters (like utm_source) from the cache key so they do not create thousands of cache entries for the same content.
