Internet Basics & History

What Is a Content Delivery Network and Why Is It Everywhere?

Learn how a content delivery network serves copies of sites from nearby servers, what it speeds up and protects, and what it costs you.

Key takeaways

  • A CDN caches copies of content on edge servers near visitors, so fewer requests travel all the way to the origin.
  • Shorter round trips make pages, video and downloads start sooner, especially for far-away users.
  • Website owners control caching mainly through HTTP headers such as Cache-Control.
  • Many CDNs also terminate TLS, filter attacks and run code at the edge.
  • Relying on one CDN concentrates risk: when it has a fault, many unrelated sites can fail together.

A content delivery network, or CDN, is a large set of servers spread across many locations that hands out copies of a website's content from somewhere close to the visitor. Instead of every request traveling to one origin server, most are answered by a nearby machine that already holds the file.

CDNs are everywhere because distance and crowds are two problems every popular service shares. A copy that sits close to you arrives sooner, and thousands of copies absorb a rush of visitors that would flatten a single server.

The problem a CDN solves

Say a small publisher runs its website on one server in a single city. A reader on the same continent gets a reasonable response. A reader on the other side of the planet waits much longer, because each exchange of messages has to cross that distance and back. Loading a page involves several such exchanges before anything appears. The limit is physical, as explained in latency and the speed of light.

Now suppose one article suddenly becomes popular. The same server must send the same images and scripts over and over, through one network connection. It slows down or stops responding.

A CDN attacks both problems by keeping copies in many places. The publisher's server, called the origin, remains the source of truth. The CDN's servers, grouped in locations called points of presence or PoPs, do most of the delivering.

How a request finds a nearby server

For a CDN to help, your request has to reach the right location without you choosing it. Two techniques do most of the work.

The first uses DNS. The site's hostname is pointed at the CDN, often with a CNAME record, and the CDN's name servers return different addresses depending on where the question seems to come from.

The second is anycast. The same IP address is announced from many locations at once, and internet routing naturally carries your packets to one that is close in network terms. Many providers combine both.

"Close" refers to the network path, which usually but not always matches geography. If your provider's connections happen to run through a distant city, that is where you may be served from.

Cache hits and cache misses

Once your request reaches an edge server, it checks whether it already holds a fresh copy.

A first visitor and a second visitor
Visitor A Visitor B Edge server Origin Request photo.jpg 1 Not cached: fetch it 2 A cache miss File plus caching headers 3 Here is photo.jpg 4 Request photo.jpg 5 Served from cache 6 A cache hit: origin not contacted Visitor A Visitor B Edge server Origin Request photo.jpg 1 Not cached: fetch it 2 A cache miss File plus caching headers 3 Here is photo.jpg 4 Request photo.jpg 5 Served from cache 6 A cache hit: origin not contacted

A miss means the edge has to fetch from the origin, or from a larger intermediate cache, before it can answer. A hit means it answers immediately. The share of requests served from cache is the hit ratio, and raising it is most of the craft of using a CDN well.

Caches have limited space, and each location fills its own. A rarely requested file may be evicted and miss again later, while a popular one stays hot everywhere.

Telling the CDN what to keep

Mostly, the origin states its wishes in HTTP response headers. The key one is Cache-Control, defined as part of HTTP caching in RFC 9111.

Cache-Control: public, max-age=31536000, immutable
Cache-Control: public, s-maxage=300, max-age=0
Cache-Control: private, no-store

The first line suits a file whose name changes whenever its contents change, such as app.3f9c.js: anyone may keep it for a year. The second lets shared caches like a CDN keep a page for five minutes while browsers revalidate each time. The third says this response belongs to one user and should not be stored at all.

CDN providers often add their own rules on top, so confirm in your provider's documentation which headers it honors and what it caches by default. Many cache static file types readily but leave HTML pages alone unless told otherwise.

When content changes before its lifetime expires, you have two options. You can purge, asking the CDN to drop its copies, or you can publish the new version under a new address. The second is more predictable. Cache invalidation covers the trade-offs, and browser caching and Cache-Control headers explains the header values.

Video and large downloads

Streaming video is a natural fit for this model. A film is not sent as one enormous file. It is cut into short segments, each a few seconds long and often prepared at several quality levels. Your player requests the segments one after another over ordinary HTTP, choosing a higher or lower quality as your connection allows.

To a CDN, each segment is just another small cacheable file. When many people watch the same program, the first request for a segment fills the cache and the rest are served from it. For a live event, thousands of players ask for the same new segment at nearly the same moment. Good CDNs hold those simultaneous misses and send a single request to the origin, a technique often called request collapsing or coalescing.

Software updates and game downloads work the same way. The file is identical for everyone, so one copy per location can serve an entire region. Integrity checks and digital signatures let your device confirm that what arrived from a nearby cache is exactly what the publisher released.

The largest services go a step further and place their own cache hardware inside access providers' networks. A popular title may then reach your home without leaving your provider at all, which lowers costs for both sides and eases pressure on the links between networks.

What a CDN usually does besides caching

Because a CDN sits between visitors and the origin, it is a natural place to do other jobs.

Jobs commonly handled at the CDN edge
Edge server Sits between visitors and your origin. Logs Shows traffic, errors and hit ratio. Edge code Runs small programs close to users. Optimization Compresses files and resizes images. Caching Serves copies of files and pages. TLS Handles encrypted connections nearby. Attack filtering Soaks up floods and blocks bad requests. Edge server Sits between visitors and your origin. Caching Serves copies of files and pages. TLS Handles encrypted connections nearby. Attack filtering Soaks up floods and blocks bad requests. Optimization Compresses files and resizes images. Edge code Runs small programs close to users. Logs Shows traffic, errors and hit ratio.

TLS termination means the encrypted HTTPS connection from your browser ends at the edge server, which then opens its own connection to the origin. The setup handshake happens over a short distance. It also means the CDN can read the traffic passing through it, so choosing a CDN is a decision about whom to trust. The leg back to the origin should be encrypted and verified too.

Attack absorption comes from sheer size. A flood of junk requests spread across many locations is easier to survive than one aimed at a single machine. See how DDoS protection services absorb attacks. For this to work, the origin's real address should not accept traffic from just anyone, or attackers can go around the shield.

Dynamic content gets some benefit too

A page built fresh for each user, such as a shopping cart, usually cannot be cached. A CDN can still help. The visitor's connection setup happens nearby, and the edge often keeps already-open connections to the origin, skipping repeated handshakes over the long haul. Some CDNs also choose better routes across their own networks.

The gain is smaller than for cached files, and no CDN can rescue a slow database query. If your origin takes three seconds to think, the page will still take about three seconds.

Who needs one, and who does not

Situation Is a CDN worth it?
Visitors spread across many countries Usually yes
Large downloads, images or video Usually yes
Sites that face traffic spikes or attacks Usually yes
An internal tool used by one office near the server Rarely
A tiny site whose host already includes caching Often already covered

Many website builders and managed hosts include a CDN without any setup. Before adding another, find out what you already have. Stacking two can make caching problems harder to trace.

What can go wrong

  • Stale content. An update does not appear because an old copy is still cached. Check the response headers and purge or rename the file.
  • Private pages cached publicly. A misconfigured rule can store a logged-in page and serve it to someone else. Mark personal responses private or no-store and test while signed in and signed out.
  • Errors that stick. Some setups cache error responses briefly, so a fixed origin still looks broken for a while.
  • Wrong visitor addresses. Your server sees the CDN's addresses. The real client address usually arrives in a header, which you should trust only when the request truly came from the CDN.
  • Shared failure. A fault at a major CDN can make many unrelated sites unreachable at once. Why big internet outages happen looks at that pattern.

You can see whether a response came from a cache by inspecting headers. This works on macOS, Linux and current Windows:

curl -I https://www.example.com/

Look for Age, which reports how long a cache has held the response, and for provider-specific headers that say hit or miss. Names differ between providers.

Setting one up, in outline

  1. List what is static (images, scripts, downloads) and what is personal (accounts, carts).
  2. Add sensible Cache-Control headers at the origin.
  3. Create the CDN configuration and point it at your origin.
  4. Test on a temporary hostname before changing DNS.
  5. Lower the DNS time to live ahead of the switch, then move the real hostname.
  6. Restrict the origin so it accepts requests from the CDN where your provider supports it.
  7. Watch the hit ratio and error rates for a few days and adjust rules.

For a site owner focused mainly on speed, how a CDN speeds up a website goes further into measuring the improvement.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Internet Basics & History →

Latest news on this topic