System Design · Architecture under constraints

How does a CDN work and when should you use one?

Easycdnedge cachingcache controlUpdated Oct 2026
Quiz this track

Short answer

A CDN caches content at edge locations close to users and serves misses from the origin. Use it for static assets and safely cacheable responses, with correct cache keys, TTLs and purge strategy.

A content delivery network keeps copies of responses in points of presence around the world. A user is routed to a nearby edge, which returns a cached response or fetches it from the origin and caches it. The result is lower latency, less origin traffic and better resilience to regional demand spikes.

What a CDN gives you

  • Lower round-trip time because the edge is geographically close
  • Origin offload for static files, images and video segments
  • TLS termination and HTTP protocol optimization at the edge
  • Absorption of traffic spikes and some DDoS protection
  • Edge logic for redirects, headers, auth checks and A/B routing

The cache key decides what counts as the same response. It usually includes the path and selected query parameters, and may include headers such as Accept-Encoding or a tenant identifier. Including too much fragments the cache; including too little can serve one user's content to another. Never cache personalized responses under a shared key.

Freshness and purge

  • Set Cache-Control max-age and s-maxage deliberately, with stale-while-revalidate where appropriate
  • Use immutable, content-hashed filenames for assets so a new deploy gets a new URL
  • Purge by tag or path when content changes, but treat purge as eventual and rate-limited
  • Use signed URLs or cookies for private content rather than relying on an obscure path
A CDN does not fix slow dynamic origin work. If every request misses because the cache key includes a unique token, the CDN only adds a hop. Measure hit ratio and origin latency, not just edge latency.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What belongs in a CDN cache key?
  2. 2How do you serve private files through a CDN?
  3. 3Why can a CDN make a slow origin look healthy?
  4. 4When would you avoid caching a response at the edge?

Say it in the interview

A CDN serves content from an edge close to the user, falling back to the origin on a miss. I use it for static assets and responses that are genuinely shareable, with a deliberate cache key and TTL. For private content I use signed URLs or tokens rather than a shared cache entry. I also track hit ratio, because a low hit ratio means the CDN is adding a hop without offloading the origin.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live System Design mock interview and get scored feedback on depth, clarity and confidence.