Content Delivery Networks
Understanding content delivery networks in system design and when to use them.
Content Delivery Networks
A Content Delivery Network (CDN) is a network of servers spread around the world. Instead of serving content from your main server, users get it from the server closest to them. This makes your website faster and reduces load on your server.
Typically, CDNs handle static content like:
- Images and videos
- CSS and JavaScript files
- HTML pages
Some CDNs, like Amazon CloudFront, can even handle dynamic content.
- Users get content faster because it's served from nearby locations.
- Your main server doesn’t get overloaded with requests the CDN can handle.
Types of CDNs
Pull CDNs fetch content from your origin server the first time someone requests it. After that, the CDN caches the content.
- You keep content on your main server
- CDN rewrites URLs to serve cached content
- TTL (Time-to-Live) controls how long content stays in the CDN
- Good for high-traffic sites where content changes often
Examples and Decisions
A news website publishes articles several times a day and has heavy traffic.
- Content changes often
- Users are global
Decision: Pull CDN → automatically caches new articles when requested
A small company website with mostly static pages and low traffic.
- Content rarely changes
- Few updates per month
Decision: Push CDN → upload content once and serve reliably
A streaming service hosts large video files. Users frequently watch the same content.
- High bandwidth usage
- Popular content reused by many
Decision: Pull CDN → cache popular videos while keeping storage efficient
- Use Pull CDN for high-traffic or frequently updated sites.
- Use Push CDN for smaller, stable sites or content that rarely changes.