AlgoInsight

System Design

What Is a Content Delivery Network (CDN)?

The reason a video loads instantly whether you're in Tokyo or Toronto is a CDN - a global network of servers caching content close to users. Here's what a CDN is, how it works, and why nearly every large system uses one.

By Admin2026-06-1814 min readcdnnetworkingcachingperformancesystem-designinfrastructure

When you stream a video, load a website's images, or download a file, it often feels instant - whether you're in Tokyo, Toronto, or Lagos. That's not because the origin server is impossibly fast; it's because the content was served from somewhere physically close to you, by a Content Delivery Network (CDN). CDNs are one of the most important pieces of infrastructure on the modern internet, and "add a CDN" is one of the most common moves in system design. This guide explains what a CDN is, how it works, and why nearly every large system uses one.

The problem a CDN solves

Start with the problem. Suppose your servers (your origin) are in one location - say, a data center in the US. A user in the US gets fast responses. But a user in Australia is physically far away, and data takes time to travel that distance - the speed of light is a real limit. Their requests cross oceans, adding latency (delay) to every load. Far-away users get a slow experience, no matter how fast your servers are, simply because of distance.

There's a second problem: if every user worldwide hits your single origin, that origin bears all the load - every image, video, and file request - which is a lot of traffic to serve and a lot of load to handle.

A CDN solves both. By caching your content on servers distributed around the world, it serves users from a nearby location (cutting latency) and absorbs most of the traffic (offloading the origin). Distance shrinks, and the origin breathes.

What a CDN is

A CDN is a geographically distributed network of servers that cache and deliver content from locations close to users. These servers - called edge servers or points of presence (PoPs) - are placed in many locations around the world. Each holds cached copies of your content, so a user's request can be served from the edge server nearest them rather than traveling all the way to your origin.

Think of it as having copies of your content in warehouses all over the world, so deliveries come from the warehouse closest to each customer instead of shipping everything from one central location. The CDN is that distributed warehouse network for your content.

graph TD
    O[(Origin server<br/>your data center)] --> E1[Edge server<br/>North America]
    O --> E2[Edge server<br/>Europe]
    O --> E3[Edge server<br/>Asia]
    U1[User in US] --> E1
    U2[User in Germany] --> E2
    U3[User in Japan] --> E3
This diagram shows a CDN. A single origin server in your data center distributes content to edge servers placed around the world - in North America, Europe, and Asia. Users are served from the edge server nearest them: a user in the US is served from the North American edge, a user in Germany from the European edge, a user in Japan from the Asian edge. Serving content from nearby reduces latency and offloads the origin.

How a CDN works

Here's the flow when a user requests content through a CDN:

  1. The user requests some content (an image, a video, a file). Through DNS-based routing, the request goes to the nearest edge server, not the distant origin.
  2. The edge server checks whether it has the content cached. Cache hit: it has a fresh copy, so it serves it immediately - fast, and the origin is never touched.
  3. Cache miss: the edge server doesn't have it (or its copy expired), so it fetches the content from the origin, serves it to the user, and caches it for next time. The first request for content at a given edge is a miss; subsequent ones are fast hits.

So a CDN works by caching content at the edge and serving from there. The first user in a region might trigger a fetch from origin, but everyone after them is served the cached copy from nearby. Over time, popular content lives cached across the edge network, and the vast majority of requests are fast hits served close to users, with only misses reaching the origin.

How users get routed to the nearest edge is itself clever - typically through DNS-based routing or anycast (where the same address is announced from many locations and the network delivers each user to the closest one). The result is that users automatically reach the edge server best positioned to serve them.

What CDNs deliver

CDNs were originally for static content - files that don't change per user: images, videos, CSS, JavaScript, downloads, fonts. Static content is ideal for caching because it's the same for everyone, so an edge server can cache one copy and serve it to many users. This remains the core CDN use case, and it's a large fraction of what most sites serve.

Increasingly, CDNs do more: they cache some dynamic content, accelerate API responses, terminate TLS at the edge (handling the secure connection closer to the user), and provide security features (absorbing attacks, filtering malicious traffic) since they sit between users and the origin. Modern CDNs have grown from "cache static files" into broad edge platforms - but the foundational job, and the one to understand first, is caching content close to users.

Cache control and invalidation

A practical challenge: if content is cached at edges worldwide, how do you update it? If you change an image but edges still serve the old cached copy, users see stale content. CDNs handle this with:

Managing this freshness-versus-performance trade-off is part of using a CDN well - you want maximum caching benefit without serving stale content.

Push vs. pull CDNs

There are two models for how content gets onto a CDN's edge servers:

Most general web content uses pull (simpler, self-managing); push suits specific scenarios with large or predictable content. Knowing both shows you understand that getting content to the edge isn't one-size-fits-all.

What makes content cacheable

Not all content benefits from a CDN equally. The ideal CDN content is:

Content that's personalized (different for each user) or constantly changing caches poorly - there's little reuse, so the cache rarely helps. This is why static assets are the classic CDN content and why dynamic, per-user content traditionally bypassed the CDN. The practical skill is recognizing which parts of your system are cacheable (the static assets, the public content) and routing those through the CDN, while dynamic per-user requests go to the origin.

The mechanism that controls all this is cache-control headers - instructions your origin sends with content telling the CDN (and browsers) how to cache it: whether it's cacheable, for how long, and whether it's public or private. Setting these correctly is how you tell the CDN exactly how to treat each piece of content.

A worked example: a video platform

To see a CDN in action, consider how a video platform serves content globally. The videos - large, static, watched by many people - are perfect CDN content. When a video is uploaded, it lives in origin storage. The first time someone in a region watches it, the nearby edge fetches it from origin (a miss) and caches it. Every subsequent viewer in that region is served the cached copy from the nearby edge - fast, without touching the origin.

For a popular video, this means the origin serves it just once per region, and the CDN's edges serve it to millions of viewers worldwide from nearby. Without a CDN, every view would stream from the origin across potentially vast distances - slow for distant users and an impossible load on the origin. With a CDN, the load is distributed across the edge network and every viewer gets low-latency delivery from close by. This is exactly why video platforms, image-heavy sites, and any global content service rely on CDNs - it's the only practical way to deliver heavy content to a worldwide audience quickly.

Modern CDNs: more than caching

CDNs have evolved beyond their original "cache static files" role into broad edge platforms:

The throughline is that the CDN's position - distributed, close to users, between them and the origin - makes it useful for far more than caching. But the foundational job remains the one to understand first: caching content close to users to cut latency and offload the origin.

When a CDN helps most (and when it doesn't)

A CDN is near-universal for large systems, but it's worth knowing where it shines and where it adds little. A CDN helps most when you have static or cacheable content (images, video, scripts, files), a geographically distributed audience (users far from your origin), high traffic (so caching offloads meaningful load), and repeatedly-requested content (so the cache gets reused). The more of these are true, the bigger the win.

A CDN helps less when content is highly personalized or constantly changing (little to cache and reuse), when your audience is concentrated near your origin (less distance to overcome), or when traffic is low (the caching benefit is small relative to the added moving part). In those cases a CDN isn't wrong, but its value is modest - and like any infrastructure, it adds a layer to configure and reason about. The judgment is matching the tool to the situation: for global, static-heavy, high-traffic content, a CDN is close to essential; for a small, dynamic, regionally-concentrated app, it may be premature. As with most system design choices, you add it when the situation genuinely calls for it, not reflexively - though for the large-scale, media-heavy systems that dominate system design discussions, it almost always does.

Why CDNs matter

Pulling it together, CDNs deliver several benefits that make them near-universal for large systems:

Interview: "Add a CDN" is one of the most common and expected moves in system design, especially for anything serving static content, media, or a global audience. The strong answer explains why: it serves content from edge servers near users (cutting latency), offloads the origin (improving scalability), and improves availability. Mentioning the cache hit/miss flow, that it's ideal for static content (images, video, JS/CSS), and the invalidation challenge (TTLs, purging, versioned URLs) shows real depth. For any system with users spread across regions or heavy static/media content, proposing a CDN signals you understand global-scale delivery.

The bottom line

A CDN is a geographically distributed network of edge servers that cache content close to users. It solves two problems at once: distance-induced latency (by serving from a nearby edge instead of a distant origin) and origin overload (by absorbing most requests at the edge). When a user requests content, they're routed to the nearest edge, which serves it from cache (a fast hit) or fetches it from the origin once and caches it (a miss). CDNs excel at static content - images, video, scripts - and increasingly handle dynamic content, TLS termination, and security too, with freshness managed through TTLs, purging, and versioned URLs.

The payoff is lower latency, reduced origin load, higher availability, and better global reach - which is why nearly every large system uses one. We cover CDNs and content delivery across System Design Fundamentals.


Go deeper

More articles