CDN

Basic System Design
≈ 3 min read

Content can be served closer to the user

If users around the world fetch files from a single data center, some requests travel a long network path, while the central system repeatedly serves the same data. A CDN — Content Delivery Network — places distributed points of presence closer to users and allows suitable requests to be served from those nodes.

client -> edge node -> origin
            |            ^
            +-- cache ---+

The client contacts a CDN edge node. If the requested object is already there, it is returned immediately. If not, the CDN fetches it from the source system — the origin — and, when the policy allows it, stores it for later requests.

Cache hit and cache miss

When the CDN serves an object from its local cache, that is a cache hit. When it must go to the origin, that is a cache miss. The higher the useful hit rate, the fewer requests and less outbound traffic remain for the central infrastructure.

The best candidates are data that is read frequently and changes relatively rarely: images, video segments, stylesheets, JavaScript files, and other public objects. Some CDNs can also work with more dynamic responses, but the caching policy then requires more care.

Freshness is part of the design

A cache creates a copy of data, which raises a question: when should that copy stop being considered current? Common tools include expiration times, versioned URLs, and explicit invalidation.

For example, a static file can be published under a new versioned name. The old copy can safely remain until it expires, while clients immediately start requesting the new object.

/assets/app.v41.js
/assets/app.v42.js
A CDN reduces distance and load, but it does not make data automatically cacheable. For personalized, fast-changing, or sensitive responses, you still need to decide whether storing them on an edge node is acceptable.

A CDN is not the main application server

A CDN is excellent at offloading repeated content delivery and can handle part of the request volume, but business operations usually continue to the origin infrastructure. It is therefore better to think of a CDN as an external distributed delivery layer, not as a replacement for the whole application.