CDNs & Caching
The problem
Sending every request across the entire globe to one origin server is slow and puts the whole load on one place — content delivery networks push copies of content physically closer to users and absorb repeat requests, cutting both latency and origin load dramatically.
Why now
HTTP fundamentals and DNS already established how a request finds and reaches a server; CDNs and caching change *which* server actually answers, and *how often* the real origin is bothered at all — an optimization layered entirely on top of the request/response model already in place.
Mental model
A cache is a shortcut: answer from a nearby copy instead of doing the full expensive work again, as long as the copy is still considered fresh. A CDN is that idea distributed geographically — many small caches near users instead of one big origin server far away — with DNS often doing the trick of directing each user to their nearest copy transparently.
Requires
- HTTP FundamentalsNetworking
HTTP caching is controlled entirely by HTTP headers (Cache-Control, ETag); you need to understand the request/response model and headers before caching rules are legible.
- DNSNetworking
CDNs typically route users to their nearest edge server by returning different IP addresses for the same domain name depending on the requester's location — a direct application of DNS resolution.
Unlocks
Used in
- Static asset delivery (images, JS, CSS) served from edge locations close to users
- API response caching to reduce load on origin servers under high traffic
- Video streaming services, which rely heavily on geographically distributed caching
- Cache invalidation — one of the famously hard problems in computing
Projects
- Inspect the Cache-Control and ETag headers on responses from a real website and explain the caching behavior they specify
- Diagram how a CDN serves a cached asset to a user without ever contacting the origin server, and when it would need to
Examples
- A Cache-Control: max-age=3600 header tells browsers and CDNs to reuse a response for up to an hour without re-checking
- A user in Tokyo and a user in London requesting the same CDN-hosted image are served from two different physically nearby edge servers
Resources
Mastery checklist
- I can explain what a CDN does and why it reduces latency
- I can interpret Cache-Control headers on a real HTTP response
- I can explain the tradeoff a cache makes between freshness and performance
- I can explain why cache invalidation is considered a genuinely hard problem