Blueprint
Infrastructure

CDN

Physics you can't code around: cross-continent round trips cost 150 ms and the speed of light won't negotiate — so move the bytes to the user instead.

01

What it is

A CDN is a geographically distributed network of edge servers that caches content close to users. It attacks the one latency you cannot engineer away — distance. Light in fibre covers roughly 100 km per millisecond one way, so New York to London has an ~80 ms floor no matter how good the code is; an edge cache 20 km from the user answers in 10–50 ms.

In interviews the CDN is mandatory in any media or global design (YouTube, Instagram, news feed assets), and the real test is whether I cleanly separate the static path from the dynamic path. Images, video segments and JS bundles go through the CDN and never touch my app servers; personalised API responses mostly don't. Getting that split right is worth more than knowing any vendor's feature list.

Say this out loud

All media and static assets go through a pull CDN with versioned URLs so I never purge — the origin only ever serves each object once per region, and my app servers never touch a byte of video.

02

The picture

usersedge PoPsorigin Tokyo Mumbai Berlin PoP ap-ne PoP ap-s PoP eu-c Origin / S3source of truth hit · 20 ms miss · 150 ms
the first request pays the full trip to origin (~150 ms); every request after that stops at the edge (~20 ms). the cache lives where the users are.
03

The variants and when to pick each

Pull CDN — the right default

The edge fetches from origin on the first miss in each region, caches the object with a TTL, and serves every subsequent request locally. Nothing to pre-provision, storage is spent only on what users actually request, and it degrades gracefully — a cold edge is a slow request, not an outage.

The cost is the first user per region eats the origin round trip, and origin must survive a burst of regional misses after a purge. For most sites this is the answer; say it and move on.

Trade-offZero lifecycle management in exchange for first-request misses per region — fine for web assets, noticeable for a global video premiere.

Push CDN — for big, predictable releases

I upload content to the edge ahead of demand: a film release, a game patch, tomorrow's app bundle. No cold-start misses anywhere, and origin sees no thundering herd at launch.

Now I own the lifecycle — deciding what's on which edge, when it expires, and paying for storage on content that may never be watched in some regions. This is Netflix's model with Open Connect boxes inside ISPs, pushing 95%+ of their traffic from the edge.

Trade-offPerfect launch-day latency, paid for with manual lifecycle management and edge storage spent on speculative placement.

Invalidation: versioned URLs beat purging

The strongest pattern is to never invalidate: put a content hash in the filename (app.3f9a2c.js), serve it with max-age=31536000, immutable, and every deploy simply references new URLs. Old versions age out untouched; there is no purge race, no stale-cache incident, no waiting on a purge API to propagate to 300 edges.

For content whose URL must stay stable (a user's avatar at a fixed path), fall back to short TTLs or the purge API — and accept purges are eventually consistent across the edge fleet.

Trade-offVersioned URLs need build-pipeline discipline and HTML that references the right hashes; purge APIs need neither but hand you propagation delay and stale-read windows.

Caching dynamic content — further than people think

CDNs are not only for files. Shared, non-personalised API responses — trending lists, public profiles, search results for common queries — can sit at the edge with a 30–60 second TTL and correct cache-control and vary headers, absorbing enormous read load for data where slight staleness is fine.

Edge compute (Cloudflare Workers, Lambda@Edge) goes further: auth checks, A/B assignment and light personalisation run at the edge over cached data. In a video design, the thing being cached is not "the file" — it's transcoded HLS/DASH segments per bitrate, which is the door into adaptive streaming.

Trade-offEvery second of edge TTL is a second of global staleness you can't recall — cheap for a trending list, disqualifying for an account balance.
04

Numbers worth memorising

Edge hit latency~10–50 ms vs ~150–300 ms cross-continent origin
Speed of light in fibre~100 km per ms one way — NY→London ≈ 80 ms RTT floor
CDN offload for media sites90%+ of bytes served from edge
1 hour of 1080p video~3 GB — why video without a CDN is a non-starter
Immutable asset TTLmax-age=31536000 (1 year) with hashed URLs
05

Where the interviewer pushes

The first push is invalidation: "the file changed — how do users see the new one?" The strong answer leads with versioned URLs — a new deploy references new hashed filenames, so nothing ever needs purging and old assets die of TTL. Then acknowledge the residual case: stable URLs that must update in place get short TTLs or an explicit purge, and purges propagate eventually, so there's a stale window I have to be able to tolerate.

The second push is "can you CDN-cache API responses, or only static files?" Yes — for shared, non-personalised data with a short TTL and correct vary headers, and it's often the cheapest read-scaling step available. The line I draw out loud: anything personalised or authenticated skips shared cache (or gets private), because a vary mistake that serves one user's data to another is a security incident, not a staleness bug.

Shows up in

Found a bug or want more?

Tell me what's broken, missing, or wrong. Every message lands in my inbox.