Infrastructure / DevOps

What is a CDN and how does it work?

What a CDN is and how it works: edge servers that cache static files near each visitor, cache hits and misses, TTLs and expiry, and why sites load faster.

  • 8 min read
  • 5 questions
  • +35 XP
Transcript

CDN, explained by cats. Kitty has a website. Hosted on one server. In one place. Nearby cats load it fast. Faraway cats wait. And wait. Every image, every page, every tuna GIF has to travel from that one server. So Kitty uses a CDN.

A Content Delivery Network. Think of it as many copy-cats in many cities. The CDN stores cached copies of static stuff, images, videos, CSS, JavaScript. Now when a cat visits, the CDN serves those files from a server close to them.

Less distance. Less waiting. Faster website. It also helps the origin server. Fewer direct requests. Less overload when lots of cats show up at once. The CDN usually doesn’t create the content. It fetches it from the origin, then keeps a copy for later.

If the cache is fresh, zoom. If it expires, the CDN asks home again. That’s a CDN. A network of nearby cat servers delivering cached content fast, so every cat gets tuna.com without crossing the whole internet.