DesignTheSystem/dev
System Design (HLD) 5 min read

CDNs: serving from close to the user

Know which content belongs on a CDN and what it saves.

Distance is latency

A request from Mumbai to a server in Virginia spends about 200 ms just travelling. A CDN keeps copies of content in many cities, so most users fetch it from nearby.

CDNs shine for content that is the same for everyone: images, video, scripts, and public pages.

What not to put there

Personal or fast-changing answers (your inbox, your balance) can't be shared, so a CDN can't cache them. Send those to your servers as usual.

Large files should live in object storage, with the CDN in front. Your servers never stream the bytes.

Key takeaways

  • A CDN serves shared, static content from near the user.
  • Personal data still goes to your servers.
  • Object storage holds big files; the CDN serves them.

Try it in the simulator: Take shared content off your servers

Put this concept into practice on Design Spotify:

  1. Build Client → Load balancer → API servers, with a Redis cache and PostgreSQL behind them, and run it.
  2. Put a CDN between the Client and the Load balancer and run again.

What to watch: Without the CDN the API servers are the bottleneck. With it, the CDN answers the shared, cacheable requests at the edge, so API server load drops sharply and p99 comes back under the target.

Check your understanding

Answer these questions interactively to test what you learned and track progress on your skill map:

  1. Which is the best fit for a CDN?
  2. Where should uploaded videos be stored?

Continue learning