DEV Community

Cover image for How a CDN works, explained for system design interviews
Gowtham Potureddi
Gowtham Potureddi

Posted on

How a CDN works, explained for system design interviews

How a CDN works, explained for system design interviews

Load a web page and its HTML, CSS, images and video all have to travel from a server to the browser — and if that server sits in one region while your users are spread across the planet, every byte crawls across thousands of miles of network, request after request. Understanding how a CDN works is understanding how that distance disappears: a content delivery network is a globally distributed network of edge servers — points of presence, or PoPs — that cache your content close to users and serve it from the nearest one, so a request from Tokyo is answered in Tokyo, not from your origin in Virginia. What a CDN is, at its core, is a giant read-through cache for the internet: the first request for a file pulls it from the origin and stores a copy at the edge; every request after that is served from the edge until the copy expires.

The reason how does a CDN work keeps coming up is that almost every large system puts a CDN in front of its static assets — and increasingly its dynamic ones — so a CDN is background infrastructure in nearly any content delivery network system design. A strong answer names what it buys you (lower latency, less origin load, bandwidth savings, and a shield against traffic spikes and DDoS) and then survives the follow-up that interviewers actually care about: you shipped a change but users still see the old file — the CDN cached it — so how do you push the new version out now? This guide walks what a candidate says out loud: why distance costs latency, how a request is routed to the nearest edge, the cache hit vs cache miss flow, and cache invalidation — the part the round turns on.

Title card for a system design interview explainer on how a CDN works, showing an origin server in one region and a world of edge PoP caches serving users nearby, with a request routed to the closest edge and a read-through cache fill from origin on a miss, on a dark citrus-and-lavender background.

Why a CDN comes up in system design interviews

A CDN rarely gets its own prompt. It shows up inside a larger design — "design a photo-sharing app," "design a video streaming service," "design a news site that handles a traffic spike" — the moment the interviewer asks how you serve images, video or static assets fast to a global audience. You say "I'll put a CDN in front of the origin," and the follow-up is the trap: what exactly does the CDN cache, how does a user reach the nearest one, and when you change a file, how do readers stop seeing the stale copy? "Add a CDN" is the easy half; the routing and the invalidation story are where real understanding shows.

The interviewer rarely lets "I'll add a CDN" stand on its own. "You deploy a CSS change, but users still see the old styles for hours — your CDN cached the old file and won't refetch until the TTL expires. Walk me through how you ship the change instantly, without waiting for that TTL to run out." That question — forcing fresh content through a cache you don't control per-request — is the one a memorised "just use a CDN" answer can never survive.

The rounds on Zynter are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: you name the CDN, and the next sentence attacks a stale asset, a cold-cache miss storm, or whether you can cache a personalised, logged-in page at all.

What the interviewer is really testing

A CDN answer is read on the same four dimensions as any design decision. Problem solving — did you reach for a CDN because distance and origin load are the real constraint, and can you name what it caches? Communication — can you say in one sentence why a cache hit at the edge beats a round trip to the origin? Technical execution — do you handle cache invalidation with versioned URLs instead of hoping the TTL is short enough, and know how routing picks an edge? Time management — did you spend your words on the hit/miss and invalidation story, not on naming a CDN vendor? Reading this guide teaches the concept; it does not teach you to defend an invalidation strategy while someone keeps asking "but the user still sees the old file."

The problem: distance costs latency, and how a request reaches the nearest edge

Start with why a CDN exists, because every benefit traces back to one fact: distance costs time. A request to a server 10,000 km away pays for the round trip at close to the speed of light through fibre — tens to hundreds of milliseconds of round-trip time (RTT) before a single byte of content comes back, and a page pulls dozens of files. Serve those files from an edge a few hundred kilometres away instead and the RTT collapses. That is the headline win, and three more ride with it:

  • Origin offload. Every request the edge answers is a request your origin never sees, so a handful of edge-cached files absorb the bulk of read traffic and your origin fleet shrinks.
  • Bandwidth savings. You pay once to push a file to the edge; the edge serves it to thousands of users, so you move far less data out of the origin.
  • Availability and DDoS absorption. The CDN's edge fleet is huge and spread out, so it can soak up traffic spikes and absorb volumetric DDoS attacks at the edge, keeping the origin reachable when a single data centre would fall over.

The other half of the problem is how a request finds the nearest edge, and this is where candidates get vague. Two mechanisms do it, and naming them is the tell:

  • Anycast. Many edge PoPs advertise the same IP address, and the internet's own routing (BGP) delivers each user's packets to the topologically nearest PoP automatically — one address, answered by whichever edge is closest.
  • DNS-based geo-routing. When the browser resolves the CDN's hostname, the CDN's DNS returns the IP of an edge chosen by the user's location (and current load and health), so the user connects to a nearby PoP from the first byte.

The sentence that scores: distance is the enemy — a far origin means high RTT on every one of a page's many requests, so a CDN caches content at edge PoPs near users and routes each request to the closest one with anycast or geo-aware DNS, cutting latency while offloading the origin, saving bandwidth, and absorbing spikes.

A diagram of CDN edge architecture, showing one origin server connected to many edge PoP caches spread across regions worldwide, with users in each region served by their nearest PoP, and a request routed to the closest edge via anycast and DNS-based geo-routing, with a note that an edge miss fetches from the origin and caches the copy.

The cache flow: cache hit vs cache miss

Once the request reaches an edge, one question decides everything: does the edge already have a fresh copy of the file? That split — cache hit vs cache miss — is the whole mechanism, and it is why a CDN is just a giant read-through cache for the internet:

  • Cache hit. The edge has a valid (unexpired) copy, so it serves it straight from the PoP without ever touching the origin. This is the fast path, and the whole point: the user gets a nearby, low-latency response and your origin sees nothing.
  • Cache miss. The edge has no copy, or the copy has expired, so the edge fetches the file from the origin (or a parent cache), stores a copy locally, sets its freshness lifetime, and then serves the user. The first user pays the full origin round trip; everyone after them, until it expires, gets a hit.

How long the edge treats a copy as fresh is set by cache-control and TTL headers the origin sends with the response — Cache-Control: max-age=... defines the time to live (TTL), the window during which the edge serves the file without re-checking the origin. That makes what to cache a real decision. Static assets — images, CSS, JS bundles, fonts, video segments — are the classic fit because they're identical for every user and change rarely, so you give them a long TTL. The subtler point, worth saying, is that CDNs now also cache dynamic content and run edge compute (small functions at the PoP), caching API responses or personalising at the edge — but anything truly per-user (a logged-in dashboard) is marked uncacheable so the edge always passes it through.

The sentence that scores: a CDN is a read-through cache — a hit is served straight from the edge with no origin round trip; a miss makes the edge fetch from origin, cache the copy for its TTL, then serve it, so the first request is slow and the rest are fast. The origin controls freshness with Cache-Control TTLs, and you cache static assets aggressively while marking per-user responses uncacheable.

A diagram of the CDN cache flow contrasting a cache hit and a cache miss, with a cache hit showing the edge PoP serving a valid cached copy directly to the user with no origin contact, and a cache miss showing the edge fetching the file from the origin, storing it with a TTL from the Cache-Control header, and then serving the user, with a note that the first request pays the origin round trip and the rest are served from the edge.

System Design
HLD · Core concept
Walk a cache hit and a cache miss out loud

Practise on Zynter →

Cache invalidation: TTL, purge, and versioned URLs

A cache that never refreshes serves stale content forever, so the real question — the one the blockquote at the top asks — is how you get a changed file out to every edge. There are three answers, and ranking them is the judgment signal:

  • TTL expiry (passive). Set a sensible max-age and the edge refetches when the copy expires. Simple, but it's a trade-off: a short TTL means fresher content but more origin misses, a long TTL means fewer misses but staler content — and neither ships a change instantly.
  • Explicit purge (active). Call the CDN's API to invalidate a specific URL (or a tag/path prefix) and the edges drop their copies, so the next request is a miss that refetches the new file. This pushes a change out on demand, but purges can take time to propagate across every PoP and don't scale well if you're invalidating constantly.
  • Versioned / fingerprinted URLs (the clean way). Instead of invalidating style.css, you ship style.a1b2c3.css — a new URL whose name includes a content hash. A new version is a new URL the edge has never seen, so it's an automatic miss that fetches the new file, while the old URL can keep its long TTL. You never invalidate anything; you just change what the HTML points at. This is why the right answer to "ship a CSS change instantly" is fingerprint the filename, not "shorten the TTL."

One more axis the interviewer may probe is how content gets to the edge in the first place: a pull CDN fills the cache lazily on the first miss (the default, zero setup, but the first user is slow), while a push CDN has you upload content to the edges ahead of time (good for large files you know will be requested, at the cost of managing what's where).

The sentence that scores: TTL expiry is the passive baseline, an explicit purge pushes a change out on demand but propagates slowly and doesn't scale, and versioned/fingerprinted URLs are the clean fix — a content hash in the filename makes every new version a brand-new URL, so it's a guaranteed miss with no invalidation at all. That's how you ship a change instantly instead of waiting on a TTL.

A diagram of CDN cache invalidation strategies, showing TTL expiry where the edge refetches only after max-age runs out, explicit purge where a CDN API call drops a URL from every edge on demand, and versioned or fingerprinted URLs where a content hash in the filename makes each new version a new URL and an automatic cache miss, plus a side note contrasting a pull CDN that fills lazily on first miss with a push CDN that uploads content to edges ahead of time.

System Design
HLD · Core concept
Defend a cache-invalidation strategy out loud

Practise on Zynter →

The pitfalls interviewers probe

A CDN is not a free win, and naming its sharp edges is what separates a real answer from a box on a diagram:

  • Stale content (the big one). A cache's hardest problem is knowing when a copy is out of date. Lean on TTLs alone and you ship stale files; the fix is versioned URLs for assets you change and explicit purges for the rest — say this before you're asked.
  • What you can't cache. Anything truly per-user — an authenticated dashboard, a cart, a personalised feed — must be marked uncacheable or you'll serve one user's data to another. The edge passes those straight through to the origin; a CDN helps the shared, static 90%, not the private 10%.
  • The cold-cache miss storm. Right after a deploy or a purge, many edges have no copy, so a burst of requests all miss and hit the origin at once (a "thundering herd"). Request coalescing at the edge and staggered TTLs blunt it.
  • It's a read optimisation, not a write path. A CDN speeds up reads of cacheable content; writes and uncacheable requests still go to the origin, so it doesn't fix an overloaded database — it just keeps read traffic off it.

The point to state plainly: a CDN trades a hard freshness problem for a huge latency and load win. You manage the freshness with TTLs plus versioned URLs and purges, you mark per-user responses uncacheable, and you remember it's a read-side cache — not a cure for every bottleneck.

How to talk about how a CDN works in an interview

The probes from every section rhyme. Master these five and you can defend a CDN in any design, not just this checklist.

  • "Why does a CDN make the page faster?" → It caches content at edge PoPs near users and serves it with a short round trip instead of a long one to a distant origin, while offloading the origin and saving bandwidth. (problem solving)
  • "How does a request reach the nearest edge?" → Anycast (many PoPs share one IP, routing delivers you to the closest) or DNS-based geo-routing (the CDN's DNS returns a nearby edge's IP). (technical execution)
  • "Cache hit versus cache miss — what happens?" → A hit is served straight from the edge; a miss makes the edge fetch from origin, cache the copy for its TTL, then serve it, so the first request is slow and the rest are fast. (communication)
  • "You shipped a change but users see the old file — now what?" → Ship a versioned/fingerprinted URL so the new version is a new URL and an automatic miss; use an explicit purge for one-off cases, not just a shorter TTL. (problem solving)
  • "What can't you cache?" → Per-user, authenticated or personalised responses — mark them uncacheable so the edge passes them through; a CDN serves the shared, static content, not private data. (technical execution)

Each maps to a debrief dimension. Reading them teaches the answers; it does not teach you to deliver them while someone keeps pushing on the stale file — that only comes from saying them out loud.

How to prepare: a short plan

You do not need a new topic for every design. You need the CDN vocabulary automatic, so when a design serves assets to a global audience you reach for the right structure without thinking.

  • Day 1: Learn why distance costs latency and what a CDN is — edge PoPs, a read-through cache, routing by anycast or geo-DNS — until you can draw origin → edges → users from memory.
  • Day 2: Drill the cache flow and invalidation — hit vs miss, Cache-Control TTLs, and the three invalidation strategies (TTL, purge, versioned URLs), plus pull vs push. This is where the follow-ups live.
  • Day 3: Place a CDN inside a real design (a photo app, a video service, a news site under a spike): say what you cache, how requests route, and how you ship a change instantly. Then do it out loud, timed, with someone insisting the user still sees the old file.

This explainer feeds the broader Top 25 system design interview questions — a CDN shows up in nearly every read-heavy design, so getting the pattern automatic pays off across the whole list.

Frequently asked questions

What is a CDN and how does it work?

A CDN — content delivery network — is a globally distributed network of edge servers, called points of presence or PoPs, that cache copies of your content close to where your users are. When a user requests a file, they're routed to the nearest edge (by anycast or geo-aware DNS) instead of to your single origin server. If that edge already has a fresh copy, it serves it directly — a cache hit — with a short, low-latency round trip. If it doesn't, it fetches the file from your origin, stores a copy locally for a set lifetime, and then serves it — a cache miss. In effect a CDN is a giant read-through cache for the internet: the first request fills the cache, and every request after that is answered near the user until the copy expires. That cuts latency, takes read load off the origin, saves bandwidth, and helps absorb traffic spikes and DDoS attacks.

Why does a CDN make a website faster?

Mostly because it kills distance. Network requests travel at roughly the speed of light through fibre, so a round trip to a server on another continent can cost tens to hundreds of milliseconds — and a single page pulls dozens of files, each paying that cost. A CDN caches those files at an edge PoP a few hundred kilometres from the user, so the round-trip time collapses and the page loads far faster. On top of the latency win, every request the edge answers is one your origin never processes, so the origin is offloaded and you move far less data out of it, which is cheaper and more resilient under load.

What is the difference between a cache hit and a cache miss?

They're the two outcomes when a request reaches an edge. A cache hit means the edge already has a valid, unexpired copy of the requested file, so it serves it straight from the PoP without ever contacting the origin — this is the fast path and the whole point of a CDN. A cache miss means the edge has no copy, or its copy has expired, so the edge fetches the file from the origin (or a parent cache), stores it locally with a freshness lifetime set by the origin's Cache-Control TTL, and then serves it to the user. The first user after a change pays the full origin round trip; everyone after them, until the copy expires, gets a hit. A high hit ratio is what makes a CDN worthwhile.

How does cache invalidation work on a CDN?

Three ways, in increasing cleanliness. First, TTL expiry: the origin sets a Cache-Control max-age, and the edge automatically refetches once that window passes — simple, but a short TTL means more origin misses and a long one means staler content, and neither ships a change instantly. Second, an explicit purge: you call the CDN's API to invalidate a specific URL or path, and the edges drop their copies so the next request refetches — this works on demand but can propagate slowly and doesn't scale if you purge constantly. Third, and the clean way, versioned or fingerprinted URLs: you put a content hash in the filename (for example style.a1b2c3.css), so a new version is a brand-new URL the edge has never cached — a guaranteed miss with no invalidation needed, while the old URL keeps its long TTL. That's how you push a CSS or JS change out immediately instead of waiting on a TTL.

How do I practise a system design interview out loud?

Reading about how a CDN works is not the same as defending an invalidation strategy while an interviewer keeps insisting the user still sees the old file. On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a design (like a photo-sharing app or a video service) on a shared canvas, and a voice interviewer follows up one question at a time ("how does a request reach the nearest edge?", "hit or miss — what happens?", "you shipped a change but it's cached — now what?"), then gives you a debrief on problem solving, communication, technical execution and time management. The score is a practice signal, not a hiring decision.

Practise it on Zynter

You can say "add a CDN." The round is won on routing, the hit/miss flow, and cache invalidation.

Pick an HLD system design round that serves assets to a global audience, put a CDN in front of the origin on the canvas, and defend it out loud to a voice interviewer that keeps asking "how does the request reach the nearest edge?" and "you shipped a change but it's cached — ship it now." — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).

Practise an HLD system design round →
Browse all interview tracks

Top comments (0)