You already know about regions (geographical zones) and AZs (datacenters within a region). There is a third type of AWS location, even closer to the end user: edge locations. They are the key to getting your content to users around the world super fast, and they work hand in hand with the CloudFront service.

The problem they solve

Imagine your website is hosted in a region in Ireland and a user opens it from Australia. Every image, video, or file has to travel halfway around the world back and forth. Even though the internet is fast, that distance adds a noticeable delay: the website loads slowly for that user.

The solution? Bring the content closer to the user. Instead of traveling from Ireland every time, we store copies of your content in many points distributed around the world. When the Australian requests an image, it is served a copy that is in Australia, not in Ireland.

What is an edge location

An edge location is an AWS point of presence, different from regions, distributed across many cities around the world (many more than regions). Its main function is to store temporary copies (cache) of content close to users.

Origin (your website in Ireland)
        │  content is copied to the edge locations
        ▼
[Edge Madrid] [Edge Tokyo] [Edge Sydney] [Edge São Paulo] ...
     │             │            │              │
  Spanish      Japanese     Australian      Brazilian
   users         users         users           users

There are hundreds of edge locations around the world, many more than regions, precisely to be as close as possible to people.

What is CloudFront

CloudFront is AWS's CDN. A CDN (Content Delivery Network) is exactly that: a network of distributed servers that serve your content from the point closest to each user.

CloudFront uses edge locations to:

  1. Store cached copies of your content (images, videos, files, even pages).
  2. Serve each request from the closest edge location to the user.
  3. Drastically reduce latency (the website loads faster).
  4. Relieve your origin server, which receives far fewer requests.

How it works, step by step

Imagine a user in Madrid requests an image from your website for the first time:

  1. First time (empty cache): CloudFront does not have the image in the Madrid edge. It requests it from your origin (Ireland), delivers it to the user, and stores a copy in Madrid.
  2. Subsequent times: another user in Madrid requests the same image. Now CloudFront already has it in Madrid and serves it instantly, without bothering Ireland.

This is called a cache hit when the content is already at the edge, and a cache miss when it has to be fetched from the origin.

Real example: Netflix uses a content delivery network to serve videos from servers close to each viewer. That's why a series starts playing almost instantly: the video doesn't travel from the other side of the world, but from a location near you.

What type of content benefits

  • Static content: images, videos, style sheets, JavaScript files, downloads. These are ideal for caching because they don't change often.
  • Dynamic content: CloudFront can also accelerate dynamic requests, optimizing the network route to your origin.

We will combine it with S3 (storage, Chapter 5) to serve static websites, and we will see it in depth in Chapter 16 (content delivery and DNS) and Chapter 28 (Lambda@Edge).

Extra advantage: security

Edge locations not only speed things up: they are also the first line of defense. By being distributed and absorbing traffic, they help protect you against denial of service attacks (DDoS) and integrate with the WAF application firewall (we'll see this in Chapter 16). Malicious traffic is filtered at the edge, far from your origin server.

The three levels of AWS presence (summary)

Now you know the three levels, from largest to closest to the user:

Level What it is What it's for
Region Geographical area with datacenters Where your application and data live
Availability Zone Independent datacenter(s) within a region High availability in case of failures
Edge location Cache point near the user Delivery speed and security

What you should remember

  • Edge locations are hundreds of AWS points distributed around the world, much closer to the user than regions.
  • CloudFront is AWS's CDN: it uses edge locations to serve your content from the point closest to each user.
  • This reduces latency (faster website), relieves your origin and improves security (defense against DDoS, integration with WAF).
  • The cache works with hits (content already copied) and misses (it has to go to the origin the first time).

In the last subchapter of Part I, we will bring together all these concepts —regions, AZ, and edge— under three key ideas: latency, resilience, and data sovereignty.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved