Architecture & opsUpdated 2026-11-20

CDN

Serving static files from an edge near the user: what a CDN caches, how it pairs with object storage, and when it adds nothing.

Copies of the shop’s posters kept in branches near every customer.

That is a CDN. The original files live in one place. A content delivery network keeps copies in many places around the world, so each visitor fetches from a branch close to them.

How it works

Without a CDN, a user in Pakistan who asks for an image reaches a server far away and waits for the whole round trip.

Code
Without: Pakistan user → distant origin server → image
With:    Pakistan user → nearby CDN edge → image

The first request for a file goes through to the origin. The edge keeps a copy. Every later request for that file, from anyone near that edge, is answered locally. The origin sees one request instead of thousands.

A common shape pairs it with object storage:

Code
User → CDN → Object storage

The storage holds the files. The CDN sits in front, cuts latency for distant users and takes repeated reads off the storage.

What belongs on a CDN

  • Images and video.
  • CSS, JavaScript and fonts.
  • Any file that is the same for every visitor.

The test is simple: does the response change per request? If not, it can be cached at the edge.

Controlling the copy

The origin tells the edge how long a copy may live, using cache headers. Two practices keep this safe:

  • Fingerprint filenames. A build writes app.3f9c.js, and a new build writes a new name. The old copy can live a year, because nothing will ever ask for that name again.
  • Purge on purpose. For a file that must change under the same name, send an explicit purge instead of waiting for it to expire.

This is caching applied at the network edge, with the same hard part: knowing when a copy is stale.

Reading the result

The number to watch is the cache hit ratio: the share of requests the edge answered without going back to the origin. A low ratio usually means something is making every URL unique, such as a query string that changes each time, or a header that varies the response more than it needs to. Check the response headers first, because most CDN problems show up there before they show up in a dashboard. A good test is to request the same file twice and confirm that the second answer reports a hit.

Where I used it

I haven't shipped this in a public project yet.

Nothing in my case studies claims a CDN I configured, so I will not claim one. PeopleCore HR serves documents through signed URLs, which is an access-control decision and a different thing from edge caching. If those files ever need to be served to distant users at volume, a CDN in front of the storage is the first place to look, with care that signed or private files are not cached for everyone.

Trade-offs

  • Stale content. An edge that holds an old copy shows an old page. Fingerprinted names remove most of this. Purges handle the rest.
  • Private content needs care. If a response depends on who is asking, a shared cache can show one user another user's data. Anything personalised must be marked as not cacheable, or varied correctly. This is the failure I worry about most.
  • Less value for dynamic pages. A fully personalised response with no cacheable part gets little from a CDN. Even then, the static assets on the same page still benefit.
  • Another party in the path. A CDN is another provider that can fail or misconfigure. Know how to send traffic straight to the origin if it does.
  • Cost moves. You pay for edge traffic instead of origin traffic. For a small audience in one country the saving may be near zero.

The rule I use: add a CDN when users are spread out or static files make up meaningful volume. For a small product with one nearby audience, a well-set cache header is enough for now.