A Content Delivery Network (CDN) is a distributed group of servers that work together to deliver web content quickly and efficiently to users based on their geographic location.

Let’s see this in action. Imagine a user in Sydney, Australia, requests a webpage hosted on a server in New York City. Without a CDN, that request has to travel across the globe, and the response has to travel back. This latency is unavoidable.

Now, let’s introduce a CDN. The CDN has servers, called Points of Presence (PoPs), strategically placed around the world. When the user in Sydney requests the webpage, the CDN intelligently routes that request not to the origin server in New York, but to the nearest PoP in, say, Sydney or Melbourne. This PoP, thanks to edge caching, already has a copy of the website’s static assets (images, CSS, JavaScript files) stored locally. The response is served from this nearby PoP, drastically reducing latency and making the page load almost instantly.

The core mechanism enabling this speed is edge caching. When content is requested and served from a CDN PoP, that PoP stores a copy of the requested files. This copy is called a cache. Subsequent requests for the same content from users geographically close to that PoP will be served directly from the cache, bypassing the need to fetch it from the origin server. This significantly reduces the load on the origin server and, more importantly, the time it takes for the user to receive the content.

The problem CDNs solve is the inherent latency of the internet. The further a user is from the web server, the longer it takes for data to travel, resulting in slow load times. This impacts user experience, conversion rates, and search engine rankings. CDNs distribute content closer to the end-user, effectively shrinking the physical distance data needs to travel.

Internally, a CDN operates by having its network of servers cache copies of your website’s static content. When a user requests a page, their request is intercepted by the CDN. The CDN’s "edge routing logic" determines the optimal PoP for that user (usually the closest one with the content cached). If the content is in the cache, it’s served immediately. If not, the PoP fetches it from the origin server, serves it to the user, and then caches it for future requests.

The exact levers you control with a CDN involve configuring how and what content gets cached. This includes:

  • Cache Invalidation: Deciding when cached content is no longer fresh and needs to be refreshed from the origin. This is crucial for dynamic content or when you update your website. You can set Time-To-Live (TTL) values, which dictate how long content stays in the cache before it’s considered stale. For example, setting a TTL of 3600 seconds (1 hour) means the CDN will try to serve the cached version for an hour before checking the origin again.
  • Cache Rules: Defining which files or URL patterns should be cached and under what conditions. You might want to cache all .jpg, .png, .css, and .js files but not dynamic API calls.
  • Origin Shielding: A feature where a subset of CDN PoPs forwards cache misses to a single "shield" server, which then contacts the origin. This further reduces the load on your origin server by consolidating requests.
  • Geographic Restrictions: You can configure a CDN to serve content only in specific regions or block access from certain countries.

One thing many people don’t grasp is that CDNs can also accelerate dynamic content to some extent, not just static assets. While the core benefit is caching unchanging files, advanced CDN configurations can use techniques like Edge Compute or request coalescing to optimize the delivery of even personalized content. For instance, a CDN can cache the response for an API endpoint for a short period if the data doesn’t change extremely rapidly, or it can intelligently route requests to the origin in a way that reduces the chance of concurrent requests overwhelming the server.

The next concept to explore is how CDNs handle SSL/TLS termination at the edge, bringing secure connections closer to the user.

Want structured learning?

Take the full Cdn course →