← All Concepts
Networking
Content Delivery Network (CDN)
A globally distributed network of servers that caches and serves content from locations close to users.
**CDN** caches content at edge servers worldwide, reducing latency by serving from the nearest point of presence (PoP).
**How it works:**
1. User requests content → DNS resolves to nearest CDN edge server
2. Edge server checks cache → if hit, serve directly
3. If miss → fetch from origin server, cache, then serve
4. Cache TTL determines how long content is cached
**Types of content:**
- **Static**: Images, CSS, JS, videos (ideal for CDN)
- **Dynamic**: API responses (cacheable with short TTL or edge compute)
**Push vs Pull CDN:**
- **Push**: You upload content to CDN proactively. Good for large, known content.
- **Pull**: CDN fetches from origin on first request. Simpler, good for most cases.
**Key features:** SSL termination, DDoS protection, image optimization, edge computing.
**Common CDNs:** CloudFront (AWS), Cloudflare, Akamai, Fastly.
Common Use Cases
- Serving static assets (images, JS, CSS) globally
- Video streaming delivery
- API acceleration for globally distributed users
- DDoS protection and traffic scrubbing
Advantages
- +Dramatically reduces latency for global users
- +Reduces origin server load
- +Built-in DDoS protection
- +SSL termination at the edge
Disadvantages
- -Cost scales with bandwidth usage
- -Cache invalidation can be slow
- -Dynamic content benefits less from CDN
- -Stale content if TTLs are too long