Amazon CloudFront
Global content delivery network (CDN) for fast content distribution
CloudFront is like having copies of your website stored in warehouses all over the world. When someone in Australia visits your site (hosted in Virginia), instead of fetching data from Virginia (slow), they get it from a nearby warehouse in Sydney (fast). CloudFront automatically caches your content at 600+ edge locations worldwide. The first person in Sydney might wait a bit while CloudFront fetches from Virginia, but everyone after that gets instant access from the Sydney cache. It's like how Netflix doesn't stream every movie from one location; they cache popular content closer to viewers. CloudFront makes your website faster globally without you managing servers in every country.
CloudFront is a CDN that caches content at edge locations worldwide, reducing latency for global users. You create distributions (configurations) pointing to origins (S3, ALB, EC2, or custom HTTP servers). When a user requests content, CloudFront routes the request to the nearest edge location. If the content is cached (cache hit), it's served immediately. If not (cache miss), CloudFront fetches from the origin, caches it, and serves it.
Key Capabilities
Key features: SSL/TLS termination, custom SSL certificates, Lambda@Edge (run code at edge locations), CloudFront Functions (lightweight JavaScript for simple transformations), geo-restriction (block/allow countries), and signed URLs/cookies (restrict access).
Gotchas & Constraints
Gotcha #1: Cache invalidations cost money; design your cache keys and TTLs carefully to minimize invalidations. Gotcha #2: CloudFront caches based on query strings, headers, and cookies; misconfigured cache behaviors can cause cache misses and high origin load. Constraints: Maximum file size is 30GB per request, and cache invalidations take 5-15 minutes to propagate globally.
A media streaming platform serves 10TB of video content daily to users worldwide. Serving directly from S3 in us-east-1 causes high latency for users in Asia and Europe, plus massive data transfer costs. They create a CloudFront distribution with S3 as the origin. When a user in Tokyo requests a video, CloudFront serves it from the Tokyo edge location (cached from a previous request) with 20ms latency instead of 200ms from Virginia. CloudFront reduces S3 data transfer costs by 60% (edge-to-user transfer is cheaper than S3-to-user). For live streaming, they use CloudFront with MediaPackage to deliver HLS streams globally. They implement signed URLs to restrict video access to paid subscribers; URLs expire after 24 hours. Lambda@Edge modifies requests to serve different video qualities based on device type (mobile vs. desktop).
The Result
10x faster content delivery, 60% cost reduction, and improved user experience globally.