CDN & Edge
Content delivery networks and edge computing — getting content closer to users, faster.
The Geographic Problem: Speed of Light Latency
Light travels at 299,792 km/s. That sounds infinitely fast until you realize it creates a hard limit: a round-trip from New York to London takes ~88ms just for the data to travel. You can't make physics faster. The only solution: move the data closer.
A user in Tokyo retrieving data from a server in Virginia experiences 140–180ms latency just from geography. This adds up fast when your page makes 50 requests.
What a CDN Does: The 5-Step Flow
1. User requests a file
User in Paris requests an image from your website.
2. CDN intercepts the request
The CDN's DNS system directs the request to the nearest edge server (Paris in this case).
3. Check the cache
The edge server checks if it has the file cached. If yes, return it immediately (10–50ms).
4. If cache miss, fetch from origin
If the file isn't cached, the edge server fetches it from your origin server (wherever it actually lives).
5. Return and cache
The edge server returns the file to the user and caches it for future requests.
What Can and Can't Be Cached
Cacheable
- Static images, videos, CSS, JavaScript
- HTML pages (with appropriate headers)
- API responses (if they don't change frequently)
- Fonts, PDFs, downloads
Not Cacheable
- Personalized content (user profiles)
- Real-time data
- Pages requiring authentication
- POST requests
- Dynamic content that changes per user
Major CDN Providers
Cloudflare
Largest CDN. Free tier includes caching, DDoS protection, and security. Massive network (200+ data centers). Company-friendly pricing.
AWS CloudFront
AWS's CDN. Native integration with AWS services. Good if you're already on AWS. More expensive for small projects.
Fastly
Enterprise-focused, real-time cache purging. Powers major media and streaming. Expensive but extremely fast.
Akamai
Original CDN (invented the concept). Media and streaming focus. Very expensive, enterprise-only.
BunnyCDN
Affordable, great for video. Growing network. Good alternative to Cloudflare for bandwidth-heavy content.
Image CDNs: Specialized Image Optimization
Images are typically the largest assets on a page. Specialized image CDNs optimize on-the-fly: resizing, format conversion (WebP), compression, and smart caching.
Cloudinary
Full-featured image management platform. API-driven transformation. Good for e-commerce and media sites.
Imgix
Real-time image processing. Clean API. Popular for media and publishing.
Bunny CDN's Image Optimization
Affordable image optimization bundled with CDN. Great value for cost-conscious projects.
Why Image CDNs Matter
Images are often 50–80% of page weight. Using an image CDN typically reduces image file size by 30–50% through:
- Format conversion: Converting JPEG to WebP saves 25–35%
- Responsive sizing: Serving a 400px image to mobile instead of 2000px desktop version
- Compression: Aggressive compression without visible quality loss
CDN Comparison
| Provider | Best For | Cost | Features | Ease of Use |
|---|---|---|---|---|
| Cloudflare | Most sites | Free–$200/month | DDoS, security, Workers | Very easy |
| AWS CloudFront | AWS-native | $0.085/GB | AWS integration | Moderate |
| Fastly | High-traffic | Custom pricing | Real-time purge | Complex |
| BunnyCDN | Video, affordability | $0.01–$0.03/GB | Video streaming | Easy |
| Cloudinary | Images | Free–$500/month | Image optimization | Easy (API) |