CDN
Content Delivery Network. A distributed network of servers that delivers web content to users based on their geographic location for faster load times.
Detailed Explanation
A CDN caches copies of your static content (images, CSS, JavaScript, fonts) on servers around the world. When a user requests content, the CDN serves it from the nearest server, reducing latency and improving load times. CDNs also provide DDoS protection, SSL termination, and bandwidth optimization.
Major CDNs include Cloudflare (largest, with free tier), Amazon CloudFront, Akamai, and Fastly. CDNs are essential for any application with global users. Modern CDNs also support edge computing—running server-side code at CDN nodes for dynamic content generation.
Why It Matters
CDNs dramatically improve performance, reduce server load, and provide security benefits. They are essential for any application serving global users.
Real-World Example
A user in Tokyo loads a website hosted in New York. Without a CDN, each request travels 10,000+ miles. With a CDN, static assets are served from a Tokyo edge server, reducing load time from 3 seconds to 300 milliseconds.
When to Use
For any website or application with users in multiple geographic regions. Even single-region applications benefit from CDN's DDoS protection and bandwidth savings.
Advantages
- Faster content delivery worldwide
- Reduced server bandwidth and load
- Built-in DDoS protection
- SSL/TLS termination at the edge
- Analytics and monitoring of traffic patterns
Disadvantages
- Adds complexity to cache invalidation
- Costs scale with traffic
- May serve stale content if not configured properly
- Dynamic content requires additional configuration
- Debugging CDN issues can be challenging
Related Terms
Frequently Asked Questions
Do I need a CDN for my website?
If you have users in multiple regions, yes. If your site is only static files, a CDN is essential for performance. If you serve dynamic content, a CDN still helps with static assets and DDoS protection.
What is the difference between a CDN and hosting?
Hosting serves your application and handles dynamic requests. A CDN caches and serves static content from edge locations near users. They work together: hosting for dynamic content, CDN for static content.
How does CDN caching work?
When a user requests a file, the CDN checks if it has a cached copy. If yes, it serves the cached version (fast). If no, it fetches from your origin server, caches it, and serves it. Subsequent requests get the cached copy until it expires.
What is cache invalidation?
Cache invalidation is the process of removing cached content from the CDN when it changes. Methods include time-based expiration (TTL), manual purge via API/dashboard, and versioned URLs (file.v2.js).
Which CDN should I use?
Cloudflare offers the best free tier with DDoS protection and edge computing. Vercel and Netlify include CDN with their hosting. AWS CloudFront integrates well with AWS services. For most projects, Cloudflare is the best starting point.