Skip to main content

What is a CDN and do you need one?

How content delivery networks work, when they pay off, and when they are overkill.

A CDN (content delivery network) is a set of servers around the world that cache your content and serve it from a location near each visitor.

How it works

  1. A visitor requests https://cdn.example.com/app.js.

  2. The nearest CDN edge answers from cache if it has the file.

  3. On a miss, the edge fetches from your origin (your server), caches it, and serves it.

Your origin handles far fewer requests; visitors get lower latency.

What a CDN gives you

  • Speed — content served from nearby, not across an ocean.

  • Offload — static and media traffic stops hitting your server and your bandwidth allowance.

  • Spike absorption — a traffic surge or attack is spread across the edge.

  • TLS at the edge — certificates and termination handled for you.

When you do NOT need one

  • Your audience is in one region, near your server.

  • Your site is small and light.

  • You have not yet optimised the basics (caching headers, compression, image sizes). A CDN in front of a slow, unoptimised site is a band-aid on a bigger problem.

Fix the basics first; a CDN multiplies what is already there, for better or worse.

The parts worth understanding

  • Cache TTL — how long the edge keeps an object. Long for fingerprinted assets; short/none for dynamic pages.

  • Cache hit ratio — the share of requests served from cache. Low ratio = little benefit; usually a caching misconfiguration.

  • Purge/invalidation — forcing the edge to drop a cached object after a change.

  • Origin shield — a single mid-tier cache that reduces origin load further.

  • WAF — many CDNs include a web application firewall; useful for bot and attack filtering.

The gotcha: two TLS legs

With a CDN there are two connections: visitor → CDN, and CDN → origin. Both need valid certificates. Set them up deliberately or you get a redirect loop or a security warning.

A sensible default

  • Small/regional site — skip the CDN; optimise caching and images.

  • Media-heavy or global — use a CDN for static assets and media first, dynamic pages later.

  • Under attack or expecting a spike — a CDN/WAF in front is the best single defence you can add.

Related reading