AI Hints
Home›System Design Tutorial›Closer and Bigger
System Design · Lesson 31 of 120

CDNs

Content close to users.

⏱ 2 min read▶ Video at 35:30🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Shoply's servers are in London. A customer in Sydney waits a third of a second for every image, just because of distance. A content delivery network, or CDN, keeps copies close to every user.

CDNs
From the video: CDNs
  • Servers in London
  • A user in Sydney
  • Distance costs time

How a CDN serves a file

ACDN has servers, called edge locations, in hundreds of cities. When the Sydney user asks for a product image, the request goes to the nearest edge. If the edge already has the image, it returns it straight away. If not, it fetches it once from Shoply's origin server, keeps a copy, and serves everyone after that.

  1. User in Sydney
  2. Nearest edge
  3. Cached? Return it
  4. Else: origin
  5. Keep a copy
How a CDN serves a file
From the video: How a CDN serves a file

What to put on a CDN

CDNs are perfect for static files, that are the same for everyone. Images, videos, style sheets, and JavaScript. Many can also cache some API responses. The benefits are big. Faster pages, much less load on your servers, and protection from traffic spikes.

keyvalue
Images and videothe biggest win
CSS and JavaScriptsame for everyone
Less origin loadedges do the work
Spike protectionabsorbs huge traffic

Summary

ACDN copies static content to edge servers near users, making pages faster and protecting your servers. Next, a server that sits in front of your servers.

Key takeaways
  • Edges near users
  • Fetch once, serve many
  • Best for static files
Next up: Reverse Proxies — a server in front of servers