CDN Fundamentals
A CDN sits between users and an origin as a globally distributed edge network. It routes requests to a nearby healthy point of presence (PoP), serves cacheable content locally when possible, and sends only misses or truly dynamic traffic back to the origin. This guide covers edge caching, TTLs, cache keys, origin shielding, purge propagation, and the DNS/anycast routing that decides which PoP answers.
What Is a CDN?
A CDN — short for content delivery network (also called a content distribution network) — is a globally distributed network of edge servers (points of presence, or PoPs) that caches content close to users to reduce latency, offload origin traffic, and help absorb load spikes or attacks.
From the user's perspective, a CDN is invisible — they just request a URL and get a fast response. Behind that URL, a network of edge servers at points of presence (PoPs) sits between the user and the origin server that owns the content. By serving cached objects from nearby PoPs, the CDN cuts latency, offloads repeat traffic from the origin, and helps prevent global demand from concentrating on one backend tier.
The core responsibilities
Edge caching
Store copies of cacheable content (images, CSS, JS, and sometimes API responses) at edge locations physically close to users.
Origin fetch
When an edge location doesn't have a requested object, it fetches it from the origin, serves it, and stores a copy for next time.
Global routing
Direct each user's request to a nearby healthy edge location, usually via anycast IP addressing or DNS-based steering. For the DNS side of that routing path, see DNS fundamentals.
Origin protection
Absorb the vast majority of repeat requests so the origin only has to handle cache misses and truly dynamic traffic.
Security at the edge
TLS termination, WAF rules, and DDoS mitigation are commonly applied before traffic ever reaches the origin infrastructure.
Visual Learning
Watch one request travel from a cold cache miss at a distant origin to a warm edge hit — then see how TTL, invalidation, and origin shielding keep that edge both fast and correct.
Why CDNs Exist
Every CDN story starts the same way: a user far from the origin, and a slow, expensive network trip.
The distance problem
Network latency has a hard physical floor — the speed of light over fiber. A user in Mumbai requesting content from a server in Virginia pays a real, unavoidable round-trip cost — roughly 130 ms just for light in fiber over ~13,000 km (illustrative: 2 × 13,000 km ÷ 200,000 km/s), and commonly 200 ms or more once routing and queueing are included — no matter how fast the origin server itself is. You can't optimize your way out of geography with a faster CPU.
Not just speed — survival
The second motivation is just as important: a single origin is a single point of load. If a piece of content goes viral, every single request would otherwise hit that one server. A CDN turns "thousands of requests hitting the origin" into "one request hits the origin, thousands are served from cache" — protecting the origin from traffic it was never provisioned to handle.
- 01Network latency is bounded by physical distance — no server-side optimization removes it.
- 02CDNs move content physically closer to users via distributed edge locations.
- 03CDNs exist to solve latency AND origin protection — not just one.
Edge Locations & Points of Presence
An edge location (or point of presence — PoP) is a small data center that sits geographically close to a group of users and holds a partial cache of origin content.
A large CDN operator runs hundreds of PoPs across the globe. Each PoP has its own edge cache, so the first request in one region can still miss even if another region is warm. Many CDNs add mid-tier caches or origin-shield layers behind those PoPs, so some misses are satisfied inside the CDN before they ever reach the origin.
Anycast routing
The same IP address is announced from every PoP; internet routing (BGP) naturally sends each user's packets to the topologically nearest PoP. Failover happens at the routing layer, not via DNS caches: when a failed PoP stops advertising the route, traffic shifts to the next-nearest PoP once BGP converges (how long this takes depends on failure detection, how the route is withdrawn, routing policy and the networks involved, and in-flight connections may break and need to reconnect).
GeoDNS routing
DNS resolves a hostname to a different IP depending on the resolver's geographic location. Simpler to operate than anycast, but failover is slower because DNS answers are cached (subject to TTL) by resolvers along the way. See DNS fundamentals for the resolver path behind that behavior.
Cache Hit vs Cache Miss
Every request that reaches an edge location results in either a cache hit (served instantly) or a cache miss (fetched from origin first, then cached).
Cache hit
The requested object already exists at the edge and hasn't expired. The response is served directly — no origin trip, minimal latency.
Cache miss
The object isn't cached (or has expired). The edge must fetch it from the origin, store it locally, and then return it to the user.
Cache-hit ratio
The percentage of requests served from cache vs total requests. This is the single most-watched CDN health metric — a low hit ratio means most traffic is still reaching the origin.
Worked trace: MISS, then HIT (illustrative)
# request 1 — cold edge
GET /img/logo.a1b2.png → 200 OK
cache-control: public, max-age=3600
x-cache: MISS # edge fetched from origin, stored a copy
# request 2 — same edge, 40 s later
GET /img/logo.a1b2.png → 200 OK
cache-control: public, max-age=3600
age: 40 # seconds this copy has been in cache
x-cache: HIT # served from the edge, origin untouchedThe copy stays fresh while age < max-age, so this one has 3,600 − 40 = 3,560 s left; after that the edge revalidates (conditional request) or refetches. Hit-ratio arithmetic (illustrative): with 10,000 requests/s reaching the edge, origin load = total × (1 − hit ratio): a 90% hit ratio sends 1,000 req/s to the origin, 95% sends 500 req/s, and 99% sends 100 req/s. Small hit-ratio gains therefore cut origin load by large factors.
TTL & Cache Expiration
Time-to-live (TTL) determines how long a cached object is considered fresh before the edge must re-check the origin.
TTL is usually set via HTTP response headers — most commonly Cache-Control: max-age=<seconds> or the older Expires header. Once the TTL elapses, the object is considered stale; the next request typically triggers a revalidation or a fresh fetch from the origin, depending on the cache directives and whether validators like ETag or Last-Modified are available.
stale-while-revalidate
Serve the stale cached copy immediately while asynchronously refreshing it in the background — users never wait on the refresh.
stale-if-error
If the origin is unreachable or erroring, keep serving the last known-good cached copy instead of failing the request outright.
Cache Invalidation
Sometimes you can't wait for a TTL to expire — cache invalidation (purging) forcibly removes a stale object from edge caches immediately.
Invalidation is typically triggered by a deployment pipeline right after publishing new content — "purge /app.js and /styles.css" — so users don't have to wait out a long TTL to see the update. Most CDNs support purging by exact URL, by tag/surrogate-key, or by wildcard pattern.
Versioned URLs (cache-busting)
A common alternative to invalidation entirely: bake a content hash into the filename (app.a1b2c3.js) so a new deployment is automatically a new cache key — no purge needed, and the old version can safely cache forever.
Static vs Dynamic Content
Not everything can — or should — be cached. Understanding what's cacheable is central to designing with a CDN.
Static content
Images, CSS, JS bundles, videos, fonts — content that's identical for every user and changes only on deployment. Ideal for long TTLs and edge caching.
Dynamic content
Personalized API responses, authenticated pages, and real-time data often bypass shared caching or use extremely short TTLs with revalidation. Even when the response itself is not cacheable, the CDN can still provide TLS termination, WAF checks, origin shielding, smart routing, or edge compute before forwarding the request.
Cacheable dynamic content
Some "dynamic-looking" content is actually cacheable for short windows — a product listing that changes every few minutes can still benefit from a 30-second edge cache, dramatically cutting origin load without serving meaningfully stale data.
Cache-Control & Cache Keys
Cache-Control tells caches whether a response may be stored and reused; the cache key decides which requests are allowed to share that stored object.
By default, most CDNs build a cache key from the request path plus (often) the full query string. Two requests differing only by ?color=red vs ?color=blue are treated as separate objects unless configured otherwise. CDNs let you customize the key — ignore tracking parameters, include selected headers such as Accept-Language, or vary on tightly scoped cookies when the response truly changes.
Cache-Control header
The primary mechanism for controlling caching behavior: public/private, max-age, no-store, no-cache, must-revalidate, and more — set by the origin, respected by the CDN.
Vary header
Tells the CDN that responses differ based on a specific request header (e.g., Vary: Accept-Encoding for gzip vs brotli) — each distinct header value gets its own cached variant.
- 01A CDN caches content at globally distributed edge locations to cut latency and shield the origin.
- 02Requests are either a cache hit (served from edge) or a cache miss (fetched from origin, then cached).
- 03TTL controls freshness; invalidation forcibly purges stale content before the TTL expires.
- 04Not all content is cacheable — static assets cache well, personalized/dynamic content usually bypasses the cache.
- 05Cache keys and the Vary header determine what counts as "the same" cached response — misconfiguring them is a common source of both wasted cache space and serious security bugs.