esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Pull CDNs: How Edge Servers Fetch Content on First Request and Keep It

Learn how a pull CDN fills its edge servers on demand, how cache headers and TTL control freshness, and what the trade-offs cost.

In short

A pull CDN fetches a file from your origin the first time a user asks for it, then keeps a copy on its edge servers for later visitors.

11 min readFree

What You Will Learn

Websites send the same files to many people: pictures, style sheets, scripts, and videos. If every request travels to one main computer far away, each visitor waits longer. A content delivery network, or CDN, helps by keeping copies of files on computers placed near users. Those computers are called edge servers. This lesson covers one way to fill those copies, called a pull CDN. It does not teach what a CDN is in general, how users are routed to the nearest edge, or push CDNs. Other lessons cover those topics.

By the end, you should be able to explain the first request and later requests, say how a copy is kept fresh, and name the trade-offs of a pull setup. Read the key words first. Each one comes back later in the lesson.

Key words

Origin server
The main server that holds the original, correct copy of your files. Your own servers are usually the origin.
Edge server
A computer in a CDN placed close to a group of users, such as in one city or region.
Cache
A temporary copy of a file, kept so the next request can be answered faster.
Cache miss
The edge server does not have a copy of the file, so it must ask the origin.
Cache hit
The edge server already has a usable copy, so it answers without asking the origin.
Header
A short label of settings sent along with a web response, before the file itself.
TTL (time to live)
How many seconds a stored copy may stay before it is treated as too old.
Cache-Control
A header from the origin that tells caches how they may store a response and for how long.
max-age
A Cache-Control setting that gives a copy's freshness time in seconds.
Purge
A command that removes a stored copy from the cache before its TTL ends.

What Is a Pull CDN?

A pull CDN is a CDN that fetches a file from your origin the first time a user asks for it. After that, it keeps a copy at the edge and uses that copy for later requests. You do not upload your files to the CDN. The CDN pulls them when they are needed. That is the reason for the name.

This model fits websites well. It is simple, because you do not need to push every file to every location ahead of time. A push CDN works the other way. There, your application uploads files to the CDN before users ask for them. Push CDNs can avoid the slow first request, but they need more planning. A push CDN is taught in its own lesson.

The pull model suits content that you cannot predict well. You may have thousands of image sizes or many pages that only a few people read. A pull CDN stores only what people actually request, so it does not fill up with files nobody uses.

How Does the Flow Work?

The flow has two cases. The first request for a file at an edge is a cache miss. Every request after that, while the copy is still fresh, is a cache hit. The steps below show the first case. The rest of this section shows the second.

  1. 1

    A user asks for a file

    A visitor's browser, the program that shows web pages, asks for a file such as a picture. The request goes to the edge server closest to that visitor.

  2. 2

    The edge looks for its copy

    It then looks for a stored copy under that key.

  3. 3

    The edge pulls from the origin

    No copy exists, so this is a cache miss. The edge sends its own request to the origin server and gets the file back.

  4. 4

    The edge stores the copy

    The edge keeps the file and sets a TTL, which says how long the copy stays fresh. The TTL usually comes from the origin's headers.

  5. 5

    The edge returns the file

    The edge sends the file to the user. The first visitor in that region receives a slower response, because the edge had to wait for the origin.

The origin server does more work on a miss than on a hit. Most of the time it does not need to serve the file, because the edge answers for it.

The steps above happen once per stored copy, not once per visitor. A tiny model makes this clear. The code below keeps a dictionary as the edge cache. The first request is a miss, and the second is a hit.

Python
edge = {}

def request(path):
    if path in edge:
        return "hit " + path
    edge[path] = "file bytes"
    return "miss " + path

print(request("/hero.jpg"))
print(request("/hero.jpg"))
print(len(edge))

Output

miss /hero.jpg
hit /hero.jpg
1

A cache hit works like this in real life. Another user asks for the same file from the same edge. The edge finds its stored copy, checks that the TTL has not ended, and sends the copy back right away. The origin is not contacted at all.

Tip

The cache key matters.

How Is Freshness Controlled?

A copy at the edge does not live forever. Once it is stored, the edge checks it against the clock. A copy that is still inside its TTL is fresh. A copy past its TTL is stale. Stale means the copy is old, but the edge still has it. Before it serves a stale copy, the edge usually asks the origin again. That second pull brings a new copy, and the clock starts over.

How Do You Set the TTL with Cache-Control?

The origin usually sets the TTL. It does this with the Cache-Control header, which travels with the file. One common setting inside that header is max-age, which gives the copy's freshness time in seconds. Here is an example header that the origin might send:

Text
Cache-Control: public, max-age=86400

The number 86400 counts seconds. That is 24 hours, because 60 seconds times 60 minutes times 24 hours gives 86400. The word public means that shared caches, such as CDN edges, may store the file. A shorter max-age means copies expire sooner, and more requests reach the origin.

  • Long max-age

    Good for files that rarely change, such as logos or fonts. Edges keep them longer, so fewer origin trips happen.

  • Short max-age

    Good for files that change often. Users see updates sooner, but the origin gets more requests.

  • No caching

    Some private responses, such as a bank page for one user, should not be stored by shared caches at all. The origin should say so in its headers.

How Do You Force an Update?

Waiting for a TTL to end is not always fine. If you fix a wrong picture, you may need users to see the fix now. There are two main tools for this.

  • Purge the cached copy

    A purge removes the copy from the edge right away. The next request becomes a cache miss, so the edge pulls the new file from the origin. Many CDNs let you purge one path or everything at once.

  • Use a versioned file name

    A versioned file name includes a version number, such as banner.v2.png. The new name makes a new cache key, so the edge has no copy and pulls the new file. Old copies are not needed, and they age out on their own.

Tip

Versioned names are often the safest choice for files that change. Old and new copies never fight over one name, and you do not need to send purge commands.

Trade-offs of a Pull CDN

A pull CDN is easy to start with, but it has costs. Here are the main points to weigh.

  • Little setup

    You do not upload files ahead of time. You point the CDN at your origin, set cache headers, and the edge fills itself as people visit.

  • Stores only what is used

    Files nobody asks for are never copied to the edge. This saves space and suits content you cannot predict.

  • Slow first visit

    The first visitor in each region waits for the edge to pull from the origin. The slowdown does happen.

A short TTL causes extra origin traffic. Copies expire often, and each expiry sends a new pull to the origin. A large set of rarely requested files causes the same problem. Each file misses at least once per region, and rare files may expire before anyone asks for them again. The origin then serves many requests that a bigger cache would have answered.

Worked Example: A News Homepage in Brazil

Imagine a news site with its origin server in Virginia, in the United States. A student in Brazil opens the homepage. The hero image, the large picture at the top, is served through a pull CDN. The nearest edge is in São Paulo. The origin sends this header with the image:

Text
Cache-Control: public, max-age=86400
  1. 1

    The first visitor asks

    The student's browser asks the São Paulo edge for the hero image. The edge has no copy, so this is a cache miss.

  2. 2

    The edge pulls the image

    The São Paulo edge sends a request to the origin in Virginia and receives the image. The student waits a little longer than usual, because the file crossed a long distance.

  3. 3

    The edge stores it with a 24-hour TTL

    The max-age value of 86400 seconds sets the TTL to 24 hours. The edge keeps the copy and starts the clock.

  4. 4

    Later visitors get cache hits

    Every other visitor in Brazil who asks for the image during the next 24 hours gets it straight from São Paulo. The origin in Virginia is not contacted for them.

  5. 5

    The copy goes stale and is refreshed

    After 24 hours, the copy is stale. The next request triggers a new pull from the origin. The new copy gets a new 24-hour TTL.

Tip

If the newsroom replaces the hero image during the day, a purge or a new file name such as hero.v2.jpg lets Brazilian visitors see the new picture without waiting 24 hours.

Check Yourself

Quick check

A pull CDN edge in Lisbon has no copy of logo.png. A visitor asks for it. What happens first?

Quick check

A team sets max-age=60 on 20,000 product photos. Most photos are viewed about once a week. What is the likely result?

Quick check

A team replaces banner.png but keeps the same file name. Users still see the old banner for hours. Which fix is best?

Key Takeaways

  • First request, cache miss

    The edge pulls the file from the origin, stores it, and returns it. The first visitor in a region waits longer.

  • Later requests, cache hits

    While the copy is fresh, the edge answers without contacting the origin.

  • Freshness comes from headers

    Cache-Control and max-age set the TTL. When it ends, the copy is stale and the edge pulls again.

  • Forcing updates

    Use a purge to remove a copy now, or a versioned file name so the edge sees a new file.

  • Trade-offs

    Pull CDNs are easy to set up and store only what is used. Slow first visits and extra origin traffic from short TTLs or many rare files are the costs.

Sources

How is this lesson?

Last updated on 17 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.