We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

CloudFront CDN

Click to play video

How does Netflix serve a 14 GB 4K video file to a user on demand? Two options include:

  • They can compress the video data as much as possible (compression).
  • They can chunk the video into smaller pieces and send it piece by piece (chunking/streaming).

But neither of those solves the problem of initial load time (how long until the first frame starts after hitting "play"). To get fast initial loads, we also need a quick round-trip time (RTT). If you're a gamer, it's basically the same as server ping: the time it takes for a request to go from your computer to the server and back.

CloudFront is AWS's content delivery network (CDN). A CDN is a network of servers distributed around the world that cache and serve content in locations that are physically close to users. In simple terms, they cache static content like images, videos, and scripts from an origin server and serve it from the nearest edge location.

CDNs solve two main problems:

  1. Latency: Bringing content physically closer to users reduces the time it takes to load.
  2. Origin Server Load: Offloading traffic from your main servers reduces bandwidth costs and prevents overload.

How CloudFront Works

  1. Origin: Your source content (S3 bucket, EC2 instance, load balancer, etc.)
  2. Distribution: CloudFront creates a "distribution," i.e., a configuration for how to route requests to your origin.
  3. Edge Locations: AWS has hundreds of edge locations worldwide.
  4. Caching: Edge locations cache content based on user requests.
  5. Delivery: When a user requests content, CloudFront serves it from the nearest edge location.