CDN
By Ankur NayakReviewed
A content delivery network stores copies of static content such as video segments, images and scripts on servers close to users, so bytes travel a short distance and the origin only serves cache misses.
How it works
A CDN is a geographically distributed set of cache servers. A user's request is steered, usually by DNS or anycast routing, to a nearby edge server. If the edge has the object it answers immediately; otherwise it fetches it from the origin once and keeps a copy for the next user in that area.
Because most bytes on the internet are popular content requested many times, a CDN can serve the overwhelming majority of traffic from the edge. That cuts latency, cuts the origin's bandwidth bill and absorbs traffic spikes.
Large video services go further and push content to the edge ahead of demand. Netflix's Open Connect, for example, fills its appliances during off-peak hours, and each deployment stores nearly the whole catalogue.
Key points
- Pull CDNs fetch on first miss; push CDNs are pre-filled ahead of demand
- Cache keys and Cache-Control headers decide what is shared and for how long
- Version file names (hash in the URL) instead of purging
- The edge also terminates TLS and absorbs DDoS traffic
When to use it, and pitfalls
Use it for
- Static assets, images, video and software downloads
- Any content requested by many users from many places
Watch out for
- Caching personalised responses by mistake (missing Vary or cache-key rules)
- Purges are slow and eventually consistent across thousands of edges
- A cold edge after new content launches sends a spike of misses to the origin
Trade-offs
Pull vs. push
Pull for long-tail web assets; push (pre-position) for a known, heavy catalogue such as video.
Pros: Pull: zero operational effort; Push: no first-request miss, fill when bandwidth is cheap
Cons: Pull: first user in a region pays the miss; Push: needs popularity prediction and storage planning
Used in
Related building blocks
Frequently asked questions
How does a CDN pick which server answers a request?
Most CDNs use DNS (returning the address of a nearby, healthy edge) or anycast (many edges announce the same IP and internet routing delivers packets to the closest). Some, like Netflix Open Connect, have a steering service that hands the client explicit URLs for specific servers.
Can a CDN cache API responses?
Yes, if the response is the same for many users and safe to share. Public, non-personalised GET responses with a short TTL are good candidates; anything that depends on the user must be excluded or keyed per user.
Sources
- What is a CDN? · Cloudflare Learning Center
- A cooperative approach to content delivery (Open Connect briefing paper) · Netflix