A Content Delivery Network (CDN) doesn’t just "speed up" your website; it fundamentally rewrites the physics of data delivery by placing copies of your content physically closer to your users, often on networks they’re already connected to.

Let’s see it in action. Imagine a user in Sydney, Australia, requesting an image from a web server located in New York City.

Without a CDN: The request travels from Sydney, across undersea cables, through multiple internet routers, to New York. The image is sent back along the same path. This involves significant latency (travel time) and can be subject to congestion at various points.

With a CDN: The request is intercepted by the CDN. The CDN has Points of Presence (PoPs) – essentially data centers – distributed globally. One of these PoPs is likely in Sydney or a nearby Australian city. The CDN checks its local cache within that PoP. If the image is cached there, it’s served directly from the Sydney PoP to the user. The entire round trip is drastically reduced because the data doesn’t need to travel to New York.

User (Sydney) -> CDN PoP (Sydney) [Cache Hit] -> Image Served

If the image isn’t in the Sydney PoP’s cache (a "cache miss"), the PoP will fetch it from the origin server in New York, then serve it to the user, and importantly, store a copy for future requests from users in that region.

User (Sydney) -> CDN PoP (Sydney) [Cache Miss] -> CDN PoP fetches from Origin (NYC) -> Image Served to User & Cached in PoP

This is the core mechanism: distributing content across a network of geographically dispersed servers. These servers are often called "edge nodes" or are part of "Points of Presence" (PoPs).

Why does this matter?

  1. Reduced Latency: The primary benefit. Data travels shorter distances, meaning faster load times for users. A user in Tokyo requesting a resource from a server in a Tokyo PoP will experience vastly lower latency than if the request had to travel to Los Angeles.
  2. Increased Availability and Redundancy: If your origin server goes down, the CDN can continue serving cached content from its edge nodes, keeping your site accessible. If a specific PoP has an issue, traffic can be rerouted to a different, nearby PoP.
  3. Offloading Traffic from Origin: By serving content from edge nodes, CDNs significantly reduce the load on your origin server. This means your server uses less bandwidth and processing power, improving its performance and potentially lowering hosting costs.
  4. Handling Traffic Spikes: CDNs are built to handle massive amounts of traffic. During a viral event or a marketing campaign that drives a surge of visitors, the CDN absorbs the load, preventing your origin server from being overwhelmed.

The Mental Model: A Distributed Library

Think of your origin server as a single, massive library in one city. When someone far away needs a book, they have to travel all the way there, get it, and come back.

A CDN is like a global chain of smaller libraries. Each branch (PoP) holds copies of the most popular books (your website’s static assets like images, CSS, JavaScript). When someone requests a book, they go to their local branch. If the book is there, they get it instantly. If not, the local branch orders it from the main library, gives it to the patron, and keeps a copy for the next person.

The Levers You Control:

  • Cache Duration (TTL - Time To Live): This is how long a piece of content stays in the CDN’s cache before the CDN checks with your origin server to see if it’s changed. A longer TTL means content is served faster from the cache but might be stale if your origin changes. A shorter TTL ensures fresher content but increases requests to your origin. For a blog post, you might set a TTL of 24 hours. For a constantly updated stock ticker, you might set it to 10 seconds.
  • Cache Invalidation/Purge: When you update a file on your origin server (e.g., a new CSS file), you need to tell the CDN to remove the old version from its cache. This is called "invalidation" or "purging." Most CDNs provide an API or a dashboard for this. You can purge specific files, directories, or the entire cache.
  • Origin Shielding: Some CDNs offer an "Origin Shield" feature. Instead of every edge PoP that has a cache miss going directly to your origin, they all first go to a designated "shielding" PoP. This shielding PoP then fetches from the origin. This further reduces the load on your origin server by consolidating cache misses.
  • Geographic Routing: CDNs intelligently route users to the closest PoP. This is usually automatic but can sometimes be configured for specific routing policies.

When a CDN serves content, it’s not just fetching it from a distant server; it’s performing a complex dance of DNS resolution, routing, and cache lookup across a globally distributed infrastructure. The initial DNS lookup for your domain is often handled by the CDN, which directs the user’s browser to the IP address of the nearest and healthiest PoP.

The most surprising thing about how CDNs handle cache invalidation is that many systems don’t truly "delete" the old file. Instead, when a purge request comes in, the CDN marks the object as expired. The next time an edge server is asked for that object, it sees it’s expired and then goes to the origin to fetch the new version, which it then serves and caches. This lazy expiration means a purge operation is often very fast, but the content might still be served from the cache for a brief period until the next request triggers the update.

The next step is understanding how CDNs handle dynamic content and API requests, which require different strategies than static asset caching.

Want structured learning?

Take the full Cdn course →