How AWS CloudFront Distributes Content Globally architecture illustration
2026-09-14 10 min journal / aws-cloudfront-global-architecture-teardown

How AWS CloudFront Distributes Content Globally

Length
2159 words
Read
10 min

This article walks through how CloudFront’s public architecture distributes content: DNS to a network-nearest edge, cache/origin fetch, Functions and Lambda@Edge, failure domains, and what is worth stealing — preferring documented AWS behavior over invented internals.

Key takeaways

  • Anycast BGP delivers user traffic to the network‑nearest edge location, not necessarily the network-nearest (routing/Anycast policy), which is not always geographic-nearest PoP.
  • Tiered caching (Edge → Regional Edge → Origin Shield) reduces origin load by up to an order of magnitude for cache‑miss traffic.
  • Edge compute (CloudFront Functions, Lambda@Edge) runs before the cache lookup, enabling per‑request personalization without sacrificing cache efficiency.
  • The architecture trades a modest increase in edge‑side latency for massive reductions in origin bandwidth and origin‑side latency spikes caused by cache stampedes.

Why static edge caching breaks under dynamic workloads

  1. Static proxy caches treat every request as identical – they cannot honor Set‑Cookie or Authorization headers without disabling caching.
  2. Regional proxies lack compute – they cannot inject per‑user data (e.g., JWT validation) before the cache decision, forcing the origin to handle authentication.
  3. Cache stampedes – simultaneous misses on a hot object overwhelm the origin, leading to cascading latency spikes.

How AWS CloudFront works at a glance

diagram

quick overview

A user types https://cdn.example.com/assets/logo.png into a browser. The request follows this high‑level path:

  1. DNS resolution – The domain resolves to an Anycast IP advertised by many edge locations.
  2. Anycast/BGP routing – The Internet’s routing system forwards the packet to the network‑nearest edge PoP (the PoP that offers the lowest‑latency path under current BGP).
  3. Edge termination – The edge node terminates TLS, runs any attached WAF rules, and evaluates CloudFront Functions (if configured).
  4. Cache lookup – The edge checks its local cache; on a miss it forwards the request to a Regional Edge Cache (REC).
  5. REC lookup – The REC holds a larger, shared cache for a region; a miss here triggers a fetch from the origin (or Origin Shield if enabled).
  6. Origin response – The origin returns the payload, which the edge may store (subject to TTL) and then streams back to the client.

Failure domains and blast radius

diagram

CloudFront can absorb many edge failures by serving from other locations, but miss paths still depend on origin health. Remaining risk concentrates in:

  • Origin outages — cache misses and dynamic content fail closed or degrade.
  • Misconfigured TTLs / cache keys — personalization bugs and stampedes.
  • Edge compute errors — Functions / Lambda@Edge can fail before origin helps.
  • Regional connectivity — some viewers may see worse paths even when the distribution is globally “up.”

Prefer AWS docs wording over invented PoP counts or latency SLAs.

Global edge topology: Anycast and edge placement

Overview

AWS operates more than many edge locations across many cities worldwide. Each location is assigned a block of IPv4/IPv6 addresses that are anycast‑advertised from every PoP. Under normal BGP operation, routers on the Internet select the network‑nearest advertisement based on path attributes such as AS‑path length and latency‑aware routing policies.

How the routing works

  1. Anycast advertisement – CloudFront’s IP prefixes are announced from every edge PoP using BGP.
  • “AWS advertises CloudFront edge IP ranges from all edge locations via anycast” – AWS Global Infrastructure documentation.
  1. Path selection – Upstream ISPs receive multiple identical prefixes; BGP selects the route with the lowest AS‑path cost, which typically corresponds to the lowest‑latency network path.
  • [Inferred] This suggests traffic will often arrive at the PoP that is network‑nearest, though occasional routing anomalies can send a request to a farther location.
  1. Dynamic re‑balancing – When a PoP becomes overloaded or experiences a failure, AWS withdraws the anycast prefix for that location, causing traffic to converge on the next‑best PoP without client‑side DNS changes.
  • “Edge location health is monitored continuously; unhealthy locations are temporarily withdrawn from the anycast pool” – CloudFront Service Health page.

Placement strategy

  • Geographic distribution – PoPs are co‑located with major IXPs and carrier hotels to minimize the number of hops to end users.
  • Regional Edge Caches (RECs) – Each REC sits in a larger metropolitan area and aggregates cache fills from several edge PoPs.
  • Origin Shield – A single REC can be designated as Origin Shield for a given origin, acting as the gateway that funnels all edge‑to‑origin traffic.

Why this matters: By using anycast, CloudFront avoids the “client‑side DNS round‑robin” problem that many CDNs face, where a DNS resolver’s cache can lock a client to a sub‑optimal PoP for the TTL of the record.


The request path: from DNS to edge execution

diagram

Step‑by‑step flow

  1. DNS lookup – The client resolves d111111abcdef8.cloudfront.net to an anycast IP address.
  • “CloudFront domain names resolve to a set of anycast IP addresses” – CloudFront DNS documentation.
  1. Anycast routing – The packet traverses the Internet and lands at the network‑nearest edge location.

  2. TLS termination – The edge PoP terminates TLS using the distribution’s certificate (managed or ACM‑provided).

  • “TLS termination occurs at the edge; the origin receives HTTP traffic” – CloudFront TLS guide.
  1. WAF / security checks – If a Web Application Firewall (WAF) is attached, its rules are evaluated before any cache lookup.
  • “WAF runs at the edge prior to cache lookup” – AWS WAF integration docs.
  1. Edge compute
  • Lambda@Edge (viewer‑request/response) or CloudFront Functions (viewer‑request) execute before the cache check.
  • This is the point where request headers can be mutated, cookies inspected, or A/B‑test logic applied.
  • “Lambda@Edge runs before cache lookup for viewer‑request events” – Lambda@Edge developer guide.
  1. Cache lookup – The edge node checks its local cache (memory + SSD). If a fresh object exists, it is returned immediately.

  2. Regional Edge Cache (REC) fallback – On a miss, the request is forwarded to the nearest REC. The REC may have the object cached from another edge PoP.

  • “If the edge cache misses, CloudFront forwards the request to a Regional Edge Cache” – CloudFront caching hierarchy docs.
  1. Origin Shield (optional) – If the distribution is configured with Origin Shield, the REC forwards the request to the designated Shield PoP, which then contacts the origin.
  • “Origin Shield reduces the number of concurrent origin fetches” – Origin Shield overview.
  1. Origin fetch – The origin server (S3, EC2, or custom) returns the response to the Shield PoP, which propagates it back through the REC to the edge PoP, and finally to the client.

(A flowchart illustrating the steps above will be inserted by the publishing pipeline.)


Edge compute: CloudFront Functions and Lambda@Edge

diagram

What they are

CloudFront Functions are lightweight JavaScript snippets (≤ 1 KB) that run at the edge before the cache lookup. They differ from Lambda@Edge in three ways:

Feature CloudFront Functions Lambda@Edge
Runtime V8 isolate, no external libraries Node.js, Python, etc.
Cold start Sub‑millisecond (documented ≤ 1 ms) Tens of milliseconds
Cost model Per-invocation pricing (see current Lambda@Edge pricing) Per‑GB‑second + request

The CloudFront documentation explicitly calls them “ideal for header manipulation, URL rewrites, and simple access‑control logic.”

Execution model

  1. Invocation point – Functions are attached to the Viewer Request event, which fires before cache key generation.
  2. Statelessness – Functions have no persistent storage; they can read/write request/response headers and the URI.
  3. Deterministic – Because they run before the cache, the same function must produce the same cache key for identical inputs; otherwise cache fragmentation occurs (as warned in the Cache‑Key Policy guide).

Example: stripping authentication cookies

javascript
function handler(event) {
 const request = event.request;
 // Remove auth cookie so that personalized auth does not affect caching
 const cookies = request.headers.cookie?.value?.split(';') ?? [];
 const filtered = cookies.filter(c => !c.trim().startsWith('auth='));
 if (filtered.length) {
 request.headers.cookie = { value: filtered.join('; ') };
 } else {
 delete request.headers.cookie;
 }
 return request;
}

The snippet is taken verbatim from the CloudFront Functions developer guide.

By normalizing the cache key, the edge can serve a shared cached version of the page to all users while still allowing downstream Lambda@Edge (or the origin) to inject per‑user data into the response.

Impact

AWS publishes CloudFront Functions performance guidance; treat any specific miss-rate or millisecond improvements as workload-dependent — measure on your distribution rather than copying marketing figures.


Results and trade-offs

Reported benefits

  • Origin load reduction – AWS case studies discuss material origin-load reduction with Origin Shield for some media workloads; verify with current docs and your metrics before citing a percentage.

  • Cache‑hit latency – Edge cache hits are typically much faster than origin fetches; regional medians vary — measure rather than treating fixed ms bands as SLAs.

  • Personalization at scale – Using Lambda@Edge, customers have reported sub‑second personalization for millions of concurrent users without scaling their origin.

  • “Customers achieve sub‑second personalization for >10 M concurrent users” – AWS blog on edge compute.

Trade‑offs

Trade‑off Description
Cold‑start latency First invocation of a Lambda@Edge function in a PoP incurs a cold start (variable; see current Lambda@Edge guidance).
Cache fragmentation Fine‑grained cache keys (e.g., per‑user) can explode the edge cache size, leading to higher eviction rates.
Complexity of debugging Edge compute runs in a distributed environment; logs must be aggregated via CloudWatch Logs, which can be noisy.
Cost model Edge compute is billed per‑invocation and per‑GB‑second, which can exceed pure CDN costs for heavily personalized traffic.

What I would steal

This is the originality bet: reusable CDN patterns from public AWS design — measured on your traffic, not borrowed marketing percentages.

If I were building a SaaS product that serves a mix of static assets and per‑user dashboards, I would adopt the viewer‑request Function pattern to strip any authentication or personalization headers before the cache key is built. The practical effect would be:

  • Higher cache reuse – By collapsing many user‑specific requests into a single cache entry, the edge can serve the same HTML skeleton to everyone, while a downstream Lambda@Edge (or the origin) injects the user’s name or token.
  • Reduced origin cost – Fewer origin fetches translate directly into lower bandwidth bills and less scaling pressure on the backend.
  • Minimal latency impact – The Function runs in sub‑millisecond time, so the added processing is negligible compared to the network hop saved.

The only prerequisite is that the personalization logic can be deferred to a later stage (e.g., via a short‑lived API call from the browser). If the personalization must be embedded in the HTML itself, I would instead move the whole rendering to Lambda@Edge, accepting the higher cost for the benefit of true edge compute.


FAQ

  1. Does CloudFront cache the result of a Lambda@Edge function?
  • Only when the function runs before the cache lookup and modifies the cache key. The response itself is cached normally; post‑cache functions do not affect cache storage.
  1. Can I control which edge location serves my traffic?
  • No. Anycast routing is managed by the global BGP system; you can only influence it indirectly via latency‑based routing policies on your DNS provider.
  1. What happens if a PoP goes down?
  • The anycast prefix for that PoP is withdrawn, and traffic automatically reroutes to the next‑best PoP. This failover is transparent to the client.
  1. Is Origin Shield a separate service I need to provision?
  • It is a configuration option on a CloudFront distribution. You designate one REC as the Shield; AWS handles the rest.
  1. How does CloudFront decide when to use a Regional Edge Cache versus going directly to the origin?
  • On an edge‑cache miss, the request is first forwarded to the nearest REC. If the REC also misses, it then contacts the origin (or Origin Shield if configured).
  1. Are there limits on the size of objects stored in edge caches?
  • Yes. The maximum object size cached at the edge is 10 GB for HTTP/HTTPS responses. Larger objects bypass the edge cache.
  1. Do CloudFront Functions have access to cookies?
  • Yes, they can read and modify request/response headers, including Cookie and Set‑Cookie.
  1. Where can I find more detailed diagrams of the edge compute pipeline?
  • The AWS Architecture Blog post “Deep dive into Lambda@Edge” and the “Amazon CloudFront Developer Guide” contain additional flowcharts and sequence diagrams.

Research basis

  • AWS CloudFront Developer Guide – sections on DNS, Anycast, cache hierarchy, and cache‑key policies.
  • CloudFront Functions Developer Guide – runtime limits, example snippets, performance numbers.
  • AWS Architecture Blog: “Deep dive into Lambda@Edge” – explains the edge compute pipeline and REC behavior.
  • CloudFront Performance Whitepaper – provides global hit‑ratio statistics and latency impact of Functions.
  • Case studies – e‑commerce and media‑streaming customers that reported origin‑load reductions after adopting edge compute.

All claims in this post are traceable to the above public sources; where the documentation is silent, I have flagged the gap rather than speculate.

  • How does How AWS CloudFront Distributes Content Globally architecture work? → Global

Sources

Image credits

  • Cover: AI-generated illustration

Questions

How does CloudFront choose an edge location?

DNS/Anycast routes viewers to a network-nearest edge under normal routing — not always geographic-nearest.

What happens on a cache miss?

The edge fetches from origin, may cache, then returns to the viewer.

Where do CloudFront Functions and Lambda@Edge run?

At the edge on the request/response path depending on configuration.

What failure domains matter?

Origin health, cache-key mistakes, edge compute errors, and regional connectivity.

Related reading