Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 1

How a CDN request is served: edge, tiers and origin

Follow one request from a DNS lookup to an edge location, through upper cache tiers and an origin shield, back to the origin; see with a small simulation why a shared upper tier cuts origin traffic; and choose between pull and push delivery.

Contentsand lesson path

On this page

  1. Why it matters
  2. The path of one request
  3. Edge tiers and the origin shield
  4. Pull or push delivery
  5. Check your understanding
  6. Apply it
  7. Review prompt

Lessons of CDN & Edge Delivery

  1. How a CDN request is served: edge, tiers and origin Concept · 20 min
  2. HTTP caching headers and cache keys Concept · 20 min
  3. Invalidation, versioned assets and signed URLs Concept · 15 min
  4. Putting a CDN in front of an origin and reading cache status Lab · 25 min
  5. Offload ratio, egress cost and edge compute Worked example · 20 min
  6. Edge delivery check Knowledge check · 6 questions

What you will learn

  • Choose pull or push CDN delivery and set Cache-Control, cache keys and TTLs for static, media and personalized responses.

Prerequisites: Caching Strategies

01. Why it matters

Distance costs time that no server upgrade can buy back. Light in optical fibre covers roughly 200,000 km per second, so if the fibre path between a user and your server is 9,000 km (an assumption, about the distance from South-East Asia to central Europe), one round trip takes at least 90 ms before any routing detour or queue. A new HTTPS connection over TCP and TLS 1.3 needs about three round trips before the first byte of the page arrives (see From a name to a response: DNS, TCP and HTTP in one trace), so that user waits a quarter of a second or more for every new connection.

A content delivery network (CDN) is a set of servers in many places, run by a provider, that sit between users and your origin (the servers that hold the real content). Each place is called a point of presence (PoP) or edge location. A nearby edge completes the connection set-up quickly and, when it holds a copy of the response, answers the request too, so the origin does not send the same bytes again.

A CDN only helps with what it may reuse, and reusing the wrong thing does harm. This lesson follows one request through a CDN, shows why providers add cache tiers, and compares the two ways content reaches the edge.

02. The path of one request

Suppose your site www.example.com is served through a CDN. A request goes through these stages:

  1. Finding an edge. Your DNS record points the name at the CDN, usually with a CNAME record to a hostname the provider gives you. The provider then steers the user to one edge in one of two ways. Some answer the DNS query with the address of a suitable PoP; CloudFront, for example, picks the PoP that can best serve the request, typically the nearest in latency. Others use anycast: many PoPs announce the same IP address, and the internet's routing protocol (BGP) delivers each packet to one of them. Anycast picks the PoP that the routing system prefers, and RFC 4786 points out that being near in routing terms does not, in general, mean the lowest round-trip time.
  2. Connection and TLS. The handshakes end at the edge, so the edge holds a certificate for your name and sees your traffic decrypted: you are trusting the provider with it.
  3. Cache lookup. The edge builds a cache key from the request, by default from the URL, and looks for a stored response under that key. If it finds a fresh one, that is a hit, and the edge answers at once.
  4. Going forward on a miss. On a miss, the edge forwards the request: to an upper cache tier if the CDN has one, otherwise to your origin. Upper tiers repeat the lookup.
  5. The way back. The response travels back through each tier. Each one decides, from the headers and its configuration, whether to store a copy and for how long.
One request through a CDN with two tiers (a sketch, not a fixed order)
user --DNS--> CDN name servers or anycast address
user --TCP+TLS--> edge PoP (near the user)
                    | hit: answer from the edge cache
                    | miss
                    v
                  upper tier or origin shield (near the origin)
                    | hit: answer, and the edge stores a copy
                    | miss (one request per object, if collapsed)
                    v
                  origin (load balancer, app servers, object storage)

Treat the sketch as one possible layout, not a fixed order. A web application firewall may run at the edge, behind the regional load balancer, or in both places. API calls, uploads and WebSocket traffic often bypass the CDN for a regional load balancer (see the skill Load balancing), or pass through it with caching off, which still gains the short handshake at the edge and reused connections from the edge to the origin. Draw your real traffic path before reasoning about it.

03. Edge tiers and the origin shield

Each edge has its own cache and sees only its own users. A file that is popular worldwide but rare in any one city misses at every edge, and each miss reaches your origin. Providers therefore group their locations into tiers. Lower tiers are the edges near users; on a miss they ask an upper tier instead of the origin. Cloudflare's Tiered Cache and CloudFront's regional edge caches work this way. An origin shield is an upper tier that you place in one location, usually the one with the best connection to your origin, so that misses from every region pass through it. CloudFront documents that requests for the same object arriving at Origin Shield together can be consolidated into as few as one origin request; this is request collapsing, which RFC 9111 section 4 describes in general terms.

The extra tier has costs: one more hop on a miss, one more location that must stay available, and sometimes a fee (the AWS price list of 19 October 2026 shows $0.0075 to $0.016 per 10,000 Origin Shield requests, by region). The script below models the benefit: 400,000 requests for 20,000 files of skewed popularity, spread over 30 edges that hold 2,000 files each, with and without an upper tier. It needs only the Python 3.12 standard library.

Python · tiers_sim.py
"""tiers_sim.py: origin requests with and without a shared upper cache tier."""

import random
from collections import OrderedDict

random.seed(42)
FILES = 20_000  # distinct files in the catalogue
EDGES = 30  # edge locations, each with its own cache
EDGE_SLOTS = 2_000  # files one edge cache can hold
REQUESTS = 400_000  # one day of requests, spread evenly over the edges

# A few files are very popular and most are rarely asked for (Zipf-like).
weights = [1 / rank**0.9 for rank in range(1, FILES + 1)]
wanted = random.choices(range(FILES), weights=weights, k=REQUESTS)
edge_of = [random.randrange(EDGES) for _ in range(REQUESTS)]


class LRU:
    """A cache that evicts the least recently used file when it is full."""

    def __init__(self, slots: int) -> None:
        self.slots, self.items = slots, OrderedDict()

    def hit(self, key: int) -> bool:
        if key in self.items:
            self.items.move_to_end(key)
            return True
        self.items[key] = True  # a miss: fetch it and keep a copy
        if len(self.items) > self.slots:
            self.items.popitem(last=False)
        return False


def run(upper_slots: int) -> tuple[int, int]:
    edges = [LRU(EDGE_SLOTS) for _ in range(EDGES)]
    upper = LRU(upper_slots) if upper_slots else None
    edge_hits = to_origin = 0
    for file, edge in zip(wanted, edge_of):
        if edges[edge].hit(file):
            edge_hits += 1
        elif upper is None or not upper.hit(file):
            to_origin += 1
    return edge_hits, to_origin


print(f"distinct files requested: {len(set(wanted)):,} of {REQUESTS:,} requests")
for label, upper_slots in (("edges only", 0), ("upper tier, 5,000", 5_000),
                           ("upper tier, 20,000", 20_000)):
    edge_hits, to_origin = run(upper_slots)
    print(f"{label:<19} edge hits {edge_hits / REQUESTS:5.1%}  "
          f"origin requests {to_origin:>7,}  offload {1 - to_origin / REQUESTS:5.1%}")
Terminal
python3 tiers_sim.py
Expected output (Python 3.12; the seed fixes the numbers)
distinct files requested: 19,799 of 400,000 requests
edges only          edge hits 54.3%  origin requests 182,743  offload 54.3%
upper tier, 5,000   edge hits 54.3%  origin requests 107,063  offload 73.2%
upper tier, 20,000  edge hits 54.3%  origin requests  19,799  offload 95.1%

Three things stand out. First, the edge hit ratio is the same in every run: the upper tier only answers the edges' misses. Second, with only edges, the origin receives 182,743 requests, nine times the number of distinct files: each popular file is fetched by each of the 30 edges, and again after every eviction. Third, an upper tier large enough for the whole catalogue brings the origin down to 19,799 requests, exactly one per distinct file. Offload here means the share of requests the CDN answered without the origin.

This is a model with invented sizes, not a measurement of any CDN; real caches are larger and traffic is not spread evenly. The shape of the result is the point: splitting traffic over many independent caches lowers each one's hit ratio, and a shared tier in front of the origin wins most of it back.

04. Pull or push delivery

There are two ways to get content into a CDN.

  • Pull (also called origin pull) is the default for most sites. You tell the CDN where the origin is, and an edge fetches each object the first time a user asks for it, then keeps it as the headers allow. It needs no upload step and stores only what users want. The price is the cold miss: the first user at each location waits for the origin, which must cope with the misses, including the burst after a purge or a release.
  • Push means you upload content to the CDN, or to a storage service that the CDN serves from, before anyone asks for it. Some providers can also pre-load objects into their caches. Push suits large files that many users will request at a known moment, and origins that cannot take a burst of misses. In return you run the upload and deletion pipeline yourself and pay to store everything you pushed.

The two often mix: a site pulls pages from its application servers and pushes videos to object storage, which the CDN then pulls from. To choose, ask how much of the catalogue is really requested, whether demand is spread out or arrives in one burst, and whether the origin survives the misses of a cold or freshly purged cache.

Whatever the delivery model, the response itself decides what may be reused. A rough first plan for the three kinds of content this skill covers:

  • Static files whose names change with their content (for example app.3f9a2c1e.js) can be cached for a year. HTML that names those files should be revalidated often, so that a new release shows up quickly.
  • Media: video segments and images of a finished recording never change, so they can be cached for a long time. A live stream's playlist changes every few seconds, so its lifetime must be shorter than the time between updates.
  • Personalised responses, such as an account page or a basket, must not be stored in a shared cache at all, unless the shared part is split from the personal part.

Lesson 2 turns this plan into exact headers and cache keys, building on Invalidation, TTLs, HTTP revalidation and the staleness budget.

05. Check your understanding

Practice check · 3 questions

Edges, tiers and the origin shield

Use the request path and the simulation above. Pick the best answer.

Q1. Users in Sydney call a JSON API hosted in Frankfurt. The team routes `/api/*` through the CDN with caching turned off. Time to the first byte of a new connection drops a lot. What explains most of the gain?
Q2. In `tiers_sim.py` you change `EDGES` from 30 to 60 and keep everything else, with no upper tier. Same 400,000 requests, same 20,000 files. What do you expect?
Q3. Your origin runs in Frankfurt; most users are in Asia and the Americas. The CDN lets you place one origin shield in any of its locations. Where should it go?
Practice only: not graded, not saved, not evidence.

06. Apply it

The practice task for this skill puts a static site and a protected media file behind a CDN free tier. First, write down the path for your own setup:

  1. Which hostname will users type, and which DNS record will point it at the CDN?
  2. Where will TLS end, and which certificate will the edge present?
  3. Which paths go through the CDN with caching, which go through it without caching, and which bypass it?
  4. Does your plan offer an upper tier or origin shield? If so, which location sits closest to your origin?
  5. Pull or push for each kind of file, and why?

07. Review prompt

Without looking back, answer in your own words:

  1. Name the five stages a request passes through in a CDN, and say what can go wrong at each.
  2. Why can anycast send a user to a PoP that is not the closest one?
  3. Why does adding more edge locations lower the hit ratio of each one, and how does an origin shield help?
  4. Give one case where push delivery is the better choice and one where pull is.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check