Notesfoundations🌱 seedling
Content Delivery Network
Also: CDN · Edge Cache · HTTP Caching
A CDN is a globally distributed HTTP cache whose edge servers near users answer repeat requests, so the origin and the long network path are skipped. HTTP headers control what it stores and for how long.
Why it exists
Distance is latency: a round trip across an ocean costs a lot of milliseconds. And an origin can't serve the whole world's reads of the same static or semi-static content.
How it works
- Edge PoPs close to users cache responses keyed by URL, plus whatever
Varynames. - Freshness:
Cache-Control: max-age/s-maxage(for shared caches),private(don't store in a shared cache),no-store, and validators (ETag,Last-Modified) for cheap revalidation. - Request collapsing: concurrent misses for one object become one origin fetch.
- Tiered caching: edges ask an upper tier before the origin, so the origin sees about one request per object.
- Serve stale:
stale-while-revalidateandstale-if-errorhide slow refreshes and origin outages. - Purge APIs invalidate content before its TTL.
Trade-offs
| Gains | Costs |
|---|---|
| low latency worldwide; origin offload; absorbs spikes and DDoS | staleness; purge discipline |
| a shared dependency: its outage is your outage |
In practice
- Fastly, June 2021: a valid customer config change triggered a latent bug and made 85% of the network return errors. Most of it was back within 49 minutes.
- Steam, December 2015: a caching config deployed during a DDoS cached pages for logged-in users, exposing about 34,000 users' account details to others.
Pitfalls
- Cache key too coarse: personalised responses cached under a URL-only key leak between users. Mark them
private, or include the rightVary/ key parts. - Long TTLs without a purge path make bad deploys sticky.
Connections
- Part of
- Caching
- Related
- Load Balancer
Recall
These cards are also in your review deck, scheduled with spaced repetition.