Should you use it?

Should you use a CDN?

Almost always yes if you serve static assets to users in more than one region. It is cheap, it cuts latency, and it shields your origin from the crowd.

A CDN is a cache that lives near your users

A CDN is a network of caches spread around the world, sitting close to where your users are. When someone in Sydney requests your logo, instead of that request crossing an ocean to a server in Virginia, it is served from an edge location a few milliseconds away. The decision is rarely agonising: if you serve shared, cacheable content to people in more than one place, a CDN is close to a free win.

It is almost always yes because the costs are low and the benefits are immediate, which is unusual here. Most of these guides are about resisting complexity you do not need yet. A CDN is one of the few that is genuinely cheap relative to what it gives back.

When a CDN earns its keep

The first win is latency, and it is physics. A round trip across the planet costs well over a hundred milliseconds before your server does any work. Serve the same asset from an edge node in the user's region and the round trip drops to single-digit or low tens of milliseconds. For a page that pulls in dozens of images, scripts, and fonts, that is the gap between snappy and sluggish.

The second win is shielding your origin. Once an asset is cached at the edge, your servers stop seeing requests for it. A traffic spike that would have hammered your origin gets soaked up across the CDN's global capacity, and your servers see a trickle.

Concretely: you ship a product page, it gets shared widely, and a hundred thousand people load it in an hour. With a CDN, your origin serves the assets a handful of times — once per edge location — and the CDN serves the rest. Without it, your origin serves all hundred thousand and you are watching dashboards turn red.

When a CDN does nothing for you

A CDN caches what is the same for many users, so it does almost nothing for content that is unique per request. A logged-in dashboard where every byte is specific to one user has nothing shareable at the edge — each response is generated fresh by your origin anyway. A CDN can still terminate TLS and proxy those requests, but the caching benefit, the whole point, is absent.

It also buys little if all your users already sit near your origin and latency is fine, or if your content genuinely changes every second and must always be the freshest version. Narrow cases, but real, and worth checking before assuming a CDN helps everything.

The traps: leaking private data and stale assets

The dangerous mistake is caching something personalised at the edge. Set the wrong cache headers on an authenticated response and the CDN may store one user's data and serve it to the next person who asks. That is a data leak from a one-line header mistake, and it is exactly why anything per-user must be explicitly marked private and uncacheable.

The other classic is the cache key. Edge caches key on the URL plus whatever you tell them to vary on — query strings, headers, cookies. Forget that two requests differ by a query parameter and you serve the wrong variant; over-vary on a cookie that changes per user and your hit rate collapses to nothing because no two requests share a key.

Then the long-TTL trap. Cache an asset with a far-future expiry and no purge plan, ship a bad version, and now that broken file is pinned in caches worldwide with no easy way to evict it. The fix is a content hash in the filename so every change is a new URL, plus a purge mechanism for when you need it.

A CDN vs serving from your origin

Serving from your origin keeps everything in one place: one server generates and ships every byte, which is simplest and the right call when responses are dynamic and per-user. The cost is that every request, from everywhere, makes the full round trip to your origin, and a spike lands entirely on your hardware.

A CDN puts a layer of regional caches in front. Shared, cacheable content gets served near the user and never touches your origin, so latency drops and spikes get absorbed. The catch is that it only helps content many users share — the more personalised your responses, the less a CDN does. So serve dynamic, private responses from the origin, and push static, shared assets to the edge. Most real sites do both.

How to roll out a CDN sanely

Start with the safe wins: static assets — images, CSS, JS, fonts. Give them long cache lifetimes and hashed filenames so updates are automatic and purging is rarely needed. This alone delivers most of the latency and origin-protection benefit with essentially no risk.

Be conservative with anything dynamic or authenticated. Default those to no edge caching, and cache only the pieces you can prove are genuinely shared and safe, with explicit headers. Done this way, a CDN is one of the lowest-regret pieces of infrastructure you can add — which is why "almost always yes" is the honest answer for any site serving real users in more than one place.

Quick reference

When it fits, when it doesn't

Reach for it when

  • You serve images, video, CSS, JS, or fonts to people spread across regions.
  • Latency matters and your origin lives far from many of your users.
  • You want to soak up traffic spikes at the edge so the origin sees a trickle.
  • You can mark assets as cacheable with sensible expiry headers.

Skip it when

  • Every response is unique and private — a logged-in dashboard with no shared, cacheable pieces.
  • All your users sit next to your origin and latency is already fine.
  • The content changes every second and must always be fresh, with no edge caching possible.

Common mistakes

  • Caching personalised or authenticated responses at the edge, serving one user’s data to another.
  • Setting expiry too long with no way to purge, so a bad deploy lingers around the world.
  • Forgetting cache keys vary on things like query strings or headers, causing wrong or fragmented hits.
Settle an argument?