codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🏗️

System Design

24 chapters

1System Design Basics2Vertical vs Horizontal Scaling3CAP Theorem4Load Balancers & Algorithms5Proxy Servers (Forward & Reverse)6Caching Strategies & Eviction7Content Delivery Networks (CDNs)8Database Replication9Database Sharding & Partitioning10Database Scaling & Sharding11Consistent Hashing12Choosing Databases (SQL vs NoSQL)13Message Queues (Kafka, RabbitMQ)14Microservices Architecture15API Gateways16Rate Limiting Algorithms17Long Polling vs WebSockets vs SSE18Heartbeat & Health Checks19Bloom Filters & Probabilistic Data Structures20Leader Election in Distributed Systems21Event-Driven Architecture22Distributed Locking23Circuit Breaker Pattern24Case Study: Design URL Shortener
SubjectsSystem Design

Content Delivery Networks (CDNs)

Updated 2026-04-30
3 min read

Content Delivery Networks (CDNs)

A Content Delivery Network (CDN) is a geographically distributed group of servers that caches content close to end users. A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, JavaScript files, stylesheets, images, and videos.

1. The Problem CDNs Solve

If your web server is located in New York, a user in Tokyo is approximately 10,800 km away. At the speed of light through fiber optic cable, a single round trip takes about 100-150ms just for the physics of the signal travel. Every image, CSS file, and JavaScript bundle requires a separate round trip.

A CDN solves this by placing copies of your static content on servers in Tokyo, London, Sydney, and hundreds of other cities. The Tokyo user downloads images from the Tokyo server (2-5ms latency) instead of from New York.

2. How CDNs Work

Push CDN

The content provider proactively uploads (pushes) content to the CDN servers. You are responsible for providing content, uploading it to the CDN, rewriting URLs, and managing expiration.

  • Best for: Sites with infrequently changing content (e-commerce product images that update monthly).

Pull CDN

The CDN lazily fetches content from the origin server when the first user requests it. Subsequent requests are served from the CDN cache.

  1. User in Tokyo requests codingstuff.io/logo.png.
  2. The CDN edge server in Tokyo checks its cache. Cache Miss!
  3. The edge server fetches logo.png from the origin server in New York.
  4. The edge server caches it and serves it to the Tokyo user.
  5. The next user in Tokyo gets it instantly from the edge cache.
  • Best for: Sites with heavy traffic where content is frequently requested.

3. CDN Benefits

  • Reduced Latency: Content is served from the nearest edge server, dramatically lowering load times.
  • Reduced Origin Load: Your origin server handles a fraction of the traffic. The CDN absorbs the vast majority.
  • DDoS Protection: Large CDN providers (Cloudflare, Akamai) can absorb massive DDoS attacks across their global network, protecting your origin.
  • High Availability: If one edge server fails, traffic is automatically rerouted to the next nearest server.

4. CDN Invalidation

The biggest challenge with CDNs is ensuring stale content is updated. If you update your website's CSS, users might still see the old cached version from the CDN.

Solutions:

  • TTL (Time-To-Live): Set an expiration time on cached content.
  • Cache Purge API: Most CDN providers offer an API to manually invalidate specific files from all edge servers globally.
  • Cache Busting: Append a version hash to filenames (e.g., style.abc123.css). When the content changes, the filename changes, forcing the CDN to fetch the new version.

Major CDN Providers: Cloudflare, AWS CloudFront, Akamai, Google Cloud CDN, Fastly.



PreviousCaching Strategies & EvictionNextDatabase Replication

Recommended Gear

Caching Strategies & EvictionDatabase Replication