DNS and CDN: Route 53 and CloudFront

Translate names to addresses with Route 53, and serve content from edge locations with CloudFront.

What is it?

DNS (Domain Name System) turns a name like www.example.com into an IP address. A resolver asks a chain of servers (the root, then the top-level domain .com, then the domain's authoritative name server) and caches the answer for the record's TTL.

Amazon Route 53 is AWS's DNS service. It registers domains, hosts DNS zones and health-checks endpoints. Its routing policies decide which answer to return:

  • Simple: one answer.
  • Weighted: split traffic by percentage (canary releases).
  • Latency-based: send users to the Region with the lowest latency.
  • Failover: primary/secondary, switching on failed health checks.
  • Geolocation / Geoproximity: route by where the user or resource is.
  • Multivalue answer: return several healthy records.

Amazon CloudFront is a content delivery network (CDN). It caches your content (static files, video, even API responses) in edge locations near users. It fetches from your origin (S3, an ALB, any HTTP server) only on a cache miss. It also handles TLS termination, absorbs DDoS traffic and integrates with AWS WAF.

Regional edge caches sit between the origin and edge locations. These larger caches hold less popular content, so fewer requests go all the way back to the origin.

CloudFront features to know

  • Distribution: the CloudFront configuration. It can have several origins (and origin groups for failover) and custom error pages. Changes take a while to deploy worldwide.
  • Behaviors: per-path settings, such as the protocol policy (for example redirect HTTP to HTTPS) and how long content stays cached.
  • Invalidations: remove cached files (such as /image.jpg) so the next request gets a fresh copy from the origin.
  • Geographic restrictions: an allow list or block list of countries.
  • Code at the edge: CloudFront Functions run lightweight JavaScript at edge locations. Lambda@Edge is more powerful and can read and change requests and responses. Both cut latency compared with calling a Lambda function in one Region.

Other services that use edge locations

  • AWS Global Accelerator: users enter the AWS network at the nearest edge location, then travel over the AWS backbone to your app. It improves performance and availability for global users (for example a single-Region app with worldwide customers, or non-HTTP traffic) without building in other Regions. It does not cache.
  • Amazon S3 Transfer Acceleration: a special bucket endpoint. Distant users upload to a nearby edge location, and the data then rides the AWS backbone to the bucket.

Exam tip: services with 'accelerat' in the name use edge locations as an on-ramp into AWS. CloudFront uses them as an off-ramp, delivering cached content to users.

Explain like I'm 10

DNS is a phone book you check before every call. A CDN is a chain of local libraries holding copies of popular books, so most readers borrow from the branch around the corner instead of ordering from a central archive across the world.

Examples

A weighted DNS record (canary)

{
  "Comment": "Send 10% to the new version",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "Name": "api.example.com",
        "Type": "CNAME",
        "SetIdentifier": "new-version",
        "Weight": 10,
        "TTL": 60,
        "ResourceRecords": [{ "Value": "api-v2.example.com" }]
      }
    }
  ]
}

Apply with aws route53 change-resource-record-sets --hosted-zone-id Z123 --change-batch file://change.json. A second record with Weight 90 pairs with it.

Inspect what a CDN returned

curl -sI https://d111111abcdef8.cloudfront.net/logo.png | grep -iE "x-cache|age|cache-control|via"
# x-cache: Miss from cloudfront     <- first request fetched from the origin
# x-cache: Hit from cloudfront      <- later requests served from the edge

Paste the headers into the HTTP headers tool to learn what Cache-Control and Age mean.

How it works

A browser asks its resolver for your name's address. Route 53, as the authoritative server, applies the routing policy and health checks and returns an answer. The resolver caches it until the TTL expires, and the browser connects to that address.

With CloudFront, the name resolves to a nearby edge location. If the edge has a fresh copy, it responds at once (a cache hit). Otherwise it fetches from the origin, stores the result according to cache headers and policies, and responds. You can invalidate cached objects when content changes.

  Browser -> Resolver -> Root -> .com TLD -> Route 53 (authoritative)
                                                |
                    answer: nearest edge IP <---+
  Browser -> Edge location --hit--> response
                   |
                  miss
                   v
               Origin (S3 / ALB)

Why does it exist?

People remember names, computers use numbers, and DNS bridges them. Distance adds latency, and the speed of light is fixed; copying content near users is the only way to make far-away users feel close.

When to use it

Use Route 53 for domains, failover and traffic shifting. Use CloudFront for global static assets, media streaming, speeding up dynamic sites and shielding origins from load.

When not to use it

A CDN adds little when your audience is in one place next to the origin, or when content is unique per request and can't be cached. Very low TTLs everywhere raise DNS query cost and latency.

Common mistakes

  • Setting a long TTL, then needing to repoint quickly during an incident.

  • Caching personalised responses by accident.

  • Forgetting that DNS changes are not instant because of resolver caching.

  • Using a CNAME at the zone apex (use a Route 53 alias record).

  • Not setting cache headers, so CloudFront cannot cache effectively.

  • Updating a file at the origin and expecting users to see it at once; cached copies stay until they expire or you create an invalidation.

  • Choosing CloudFront for faster uploads into S3 from far away; that is S3 Transfer Acceleration.

  • Thinking Global Accelerator caches content like CloudFront; it only routes traffic over the AWS network.

Practice exercises

  1. Easy:

    Describe each step of DNS resolution for shop.example.com starting from an empty cache.

  2. Medium:

    Pick a Route 53 routing policy for: (a) blue/green rollout, (b) users nearest their Region, (c) automatic standby site.

  3. Medium:

    Look at a real site's response headers in the HTTP headers tool and determine whether a CDN served it.

  4. Hard:

    Design caching rules for a site with static assets, a logged-in dashboard, and a public API. What do you cache, for how long, and how do you invalidate?

Interview questions

What is Route 53?

AWS's scalable DNS service, which also supports domain registration, health checks, and routing policies.

What is an edge location used for?

Caching and delivering content close to users, as CloudFront does.

What is TTL?

How long a DNS answer (or cached object) may be reused before being fetched again.

Exam-style: Which service reduces latency for global users by caching content at edge locations?

Amazon CloudFront.

Exam-style: Which Route 53 routing policy sends users to the lowest-latency Region?

Latency-based routing.

Exam-style: Users around the world upload large files to one S3 bucket and uploads are slow. What helps?

Amazon S3 Transfer Acceleration.

Exam-style: A single-Region application with global users, including non-HTTP traffic, needs better performance and availability via the AWS network. Which service?

AWS Global Accelerator.

How do you make CloudFront serve an updated file immediately?

Create an invalidation for that path so edge locations fetch the new version from the origin.

CloudFront Functions vs Lambda@Edge?

Both run code close to users. CloudFront Functions are lightweight JavaScript for simple, high-volume request tweaks; Lambda@Edge is more powerful and can work with both requests and responses.

Exam-style: How can a company stop users in certain countries from accessing content served by CloudFront?

Use CloudFront geographic restrictions (an allow list or block list of countries).