SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
  • CDN
  • Distributed Cache Architecture
  • Cache Stampede
  • Cache Warming
  • Hot Keys
  • Cache Penetration and Cache Avalanche
  • CDN Push vs Pull
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Caching/Distributed Caching

CDN Push vs Pull

Upload files to the CDN yourself, or let it fetch them from your server on the first request?

โฑ 11 min readIntermediateHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A CDN keeps copies of your files in many cities. The question here is how the files get there. With a pull CDN, the edge fetches a file from your server the first time someone asks. With a push CDN, you upload the file to the CDN yourself, before anyone asks.

  • Pull (origin pull): easy to set up. The first user at each location waits for the trip to your server, then everyone nearby is fast until the copy expires.
  • Push: you control exactly what is on the CDN. Nobody pays for a first-request miss, but you must upload, update and clean up files yourself.
  • Most websites use pull. Push suits a small set of big, known files, like software releases.

02Concept: What is it?

A CDN (content delivery network) is a set of servers in many places, called edge locations. A user is sent to a nearby edge, and the edge answers from its saved copy. Your own server, where the original file lives, is called the origin.

Pull: the edge asks when it needs a file

You point the CDN at your origin and change your page links to use the CDN address. The edge starts empty. When the first user in Tokyo asks for logo.png, the Tokyo edge has no copy (a cache miss), so it fetches the file from your origin, saves it, and sends it to the user. The next user in Tokyo gets the saved copy at once (a cache hit). After the file's TTL runs out, the edge asks the origin again.

Push: you put the file on the CDN first

With push, you upload the file to the CDN's storage as part of your release. The CDN copies it to its edges (how many and how fast depends on the product). Users never trigger a fetch from your origin, because the file is already there. When you change the file, you upload the new version and remove the old one.

Pull and push, side by side
Pull CDN
๐Ÿ‘คUser
โ†’โ†“1. ask
๐Ÿ“Edgeempty at first
โ†’โ†“2. miss: fetch
๐Ÿ–ฅ๏ธOrigin
First user at each edgeslower (origin trip)
Everyone after thatfast (edge hit)
Push CDN
๐Ÿง‘โ€๐Ÿ’ปYouupload at release
โ†’โ†“1. push
๐Ÿ“Edgesalready filled
โ†’โ†“2. serve
๐Ÿ‘คUser
First user at each edgefast (already there)
Your workupload and clean up
Pull is triggered by users. Push is triggered by you.
๐Ÿง The one-line difference
Pull fills the edge when someone asks. Push fills it when you decide.

03Real-Life Example

๐ŸตTwo Ways to Stock Neighbourhood Shops
A publisher wants its books close to readers in every city. In the first plan, each local bookshop starts with empty shelves. When a customer asks for a book, the shop phones the publisher's warehouse, gets a copy, and keeps a few for later. The first customer waits a few days. Later customers are served at once. This is pull.

In the second plan, the publisher ships a box of the new book to every shop before the launch day. Nobody waits, but the publisher must pack boxes, decide how many to send, and collect the old edition when a new one arrives. This is push.
Bookshops
CDN
The publisher's warehouse
The origin server
A local bookshop
An edge location
Phoning the warehouse for a missing book
A cache miss and origin fetch
Keeping a few copies after the first order
Caching with a TTL
Shipping a box before launch day
Pushing a file to the CDN
Collecting the old edition from every shop
Purging or replacing an old file
A regional depot that serves many shops
An origin shield (a middle cache layer)
The life of one file on a pull CDN
๐Ÿ™‹First requestedge is empty
โ†’โ†“miss
๐Ÿ–ฅ๏ธOriginsend the file
โ†’โ†“
๐Ÿ’พEdge saves itfor the TTL
โ†’โ†“hit
โšกNext requestsserved at once

04Why Do We Need It?

๐ŸงญChoose who does the work
Pull lets the CDN do the work lazily. Push lets you do it on your schedule. Each fits different files.
๐Ÿ–ฅ๏ธProtect the origin
Without a CDN every user hits your server. Pull cuts that to one fetch per edge per expiry. Push cuts it to zero.
โšกAvoid the first-user penalty
On pull, the first user at each location pays for the long trip. Push or pre-warming removes that wait.
๐ŸŽ›๏ธControl and predictability
Push means you know what is on the CDN and when. Pull depends on traffic and TTL.
๐ŸงนLess operations
Pull needs almost no tooling. Push needs an upload step in every release.
๐Ÿ’ธCost shape
Pull pays origin traffic when files expire. Push pays for storing every file you push, used or not.
Pull is the lazy, low-effort default. Push is the controlled option for a few big, known files.

05Where Do We Use It?

๐ŸŒWebsites and apps (pull)
Images, scripts and style sheets. Many files, unpredictable use, changes with every deploy.
๐Ÿ›’E-commerce (pull)
Thousands of product images. Most are rarely seen, so there is no point in pushing them all.
๐Ÿ“ฆSoftware downloads (push)
An installer or update that everyone will fetch on launch day. Upload it ahead of time.
๐ŸŽฌVideo drops (push)
A big release at a set time. Push the files before, so the first viewers are not slow.
๐ŸŽฎGame patches (push)
A patch is large and the demand arrives all at once. Pre-positioning avoids hammering the origin.
๐Ÿ”€Hybrid
Pull for the long tail of files, push or pre-warm for the few that matter most.

06Types / Parts / How It Works

Push vs pull

Pull (origin pull)Push
Who fills the edgeThe edge, on the first requestYou, ahead of time
First user at an edgeWaits for an origin fetchServed at once
Set-up effortLow: point the CDN at your originHigher: an upload step and file management
Origin needs to be upYes, whenever a copy is missing or expiredOnly while you upload
Updating a fileWait for the TTL, purge, or use a new URLUpload the new version yourself
Storage on the CDNOnly files that were asked forEverything you push, used or not
Best forMany files, unpredictable demandA few big files, known in advance

Pull in practice: the headers that matter

On a pull CDN, your origin's response headers tell the edge how long to keep the file. See HTTP Caching (Cache-Control, ETag) for the details. A typical response for a versioned file looks like this:

Illustrative response headers from the origin
Cache-Control: public, max-age=31536000, immutable
ETag: "9f3c1a"
Content-Type: text/css

Two helpers that apply to both

๐Ÿ›ก๏ธOrigin shield
A middle cache between the edges and your origin. Many edges ask the shield, and the shield asks the origin once. This cuts origin load on pull, and makes a first request faster on average.
๐Ÿท๏ธVersioned file names
Put a version or content hash in the name (app.3f9a.js). A new version is a new URL, so there is nothing old to purge. This makes both models much easier to update.
Origin shield on a pull CDN
๐Ÿ“EdgesLondon, Tokyo, Mumbai
โ†’โ†“miss
๐Ÿ›ก๏ธShieldone middle cache
โ†’โ†“one fetch
๐Ÿ–ฅ๏ธOrigin
Edge Shield Origin
Without a shield, every edge fetches from the origin. With one, the origin is asked once.
VisualizerPush vs pull: who pays for the first request?Switch between pull and push, and watch the first request at each city. On pull, change the TTL, publish a new version, and then try the purge. Increase the requests to see the hit ratio improve.
How does the file get to the edges?
Each square is one user request, left to right over 20 minutes. Green = edge hit, cyan = went to the origin, red = stale (old version served). The dashed bar marks the new version going live.
London
Mumbai
Tokyo
Sรฃo Paulo
Edge hit ratio
67%
32 of 48
Origin transfers
16
edge fetches
Avg response
78 ms
illustrative
Stale responses
0
none
With a TTL of 5 min the edges keep expiring the file, so 16 requests went all the way to the origin (hit ratio 67%). A longer TTL means fewer trips, but slower updates.

A simplified model with fixed request times and no random numbers. The response times (20 ms from an edge, plus an illustrative round trip to the origin for each city, plus 30 ms to build the answer) are made-up round numbers, not measurements. Push upload time is ignored.

07How to Use It / Steps / Implementation

Choosing and running push or pull

  1. 1
    Start with pull
    For most sites it is enough. Put the CDN in front of your origin, and let it fetch what users ask for.
  2. 2
    Set cache headers on the origin
    Give static files a long Cache-Control max-age. Give pages or APIs a short one or none. The CDN follows what the origin says.
  3. 3
    Use versioned file names
    Name files with a hash or version, so a change is a new URL. Then you almost never need to purge.
  4. 4
    Add an origin shield if the origin is small
    It reduces how often many edges all go to the origin at the same time.
  5. 5
    Use push for big, scheduled content
    For a launch-day download or video, upload ahead of time and check that it is available at the edges before you announce it.
  6. 6
    Automate uploads and clean-up
    Put the push step in your release pipeline. Remove files you no longer need, so storage does not grow without end.
  7. 7
    Pre-warm if you stay on pull
    Before a big event, request the key files once through each region, so the first real users get hits.
  8. 8
    Measure the hit ratio
    Track the share of requests answered by the edge, origin traffic and the time to first byte by region.
๐Ÿ’กPull plus pre-warming is a hybrid
You can keep the simplicity of pull and still avoid the cold start: send a few requests to the important files before the launch. Some CDNs offer a preload or pre-fetch feature for this.
โš ๏ธNever cache private pages on a shared edge
A page that contains one user's data must not be cached as public. Use Cache-Control: private or no-store for it, or the edge may serve it to the next user.

08Key Terms to Know

TermMeaning in easy words
OriginYour own server, where the original files live
Edge locationA CDN server near the users that keeps copies of files
Pull CDN (origin pull)The edge fetches a file from the origin the first time it is asked for
Push CDNYou upload files to the CDN yourself, ahead of time
Cache hitThe edge already has a fresh copy and answers at once
Cache missThe edge has no usable copy, so it must go to the origin
TTLHow long an edge may reuse a copy before it must check again
Hit ratioThe share of requests answered by the edge without going to the origin
Purge / invalidateTell the CDN to throw away a file, so the next request fetches a new one
Origin shieldAn extra cache layer between the edges and the origin, to reduce origin load
Pre-warmingRequesting files ahead of time so the first real users get hits

09Pros, Cons and Trade-offs

โœ… Pros
  • Pull: simple set-up and little day-to-day work
  • Pull: only popular files use CDN storage
  • Push: no first-request wait at any edge
  • Push: you know exactly what is on the CDN
  • Both: your origin carries far less traffic
โš ๏ธ Cons
  • Pull: the first user at each edge pays the origin trip
  • Pull: old copies stay until the TTL ends or you purge
  • Push: you must upload, update and clean up
  • Push: you pay to store files that nobody may ask for
  • Both: wrong cache headers can serve stale or private data

Trade-offs

ChoiceWe gainWe lose
PullLittle effort and lazy fillingA slow first request at each edge, and a dependency on the origin
PushFast first request and full controlUpload work and storage cost, and a process you must not forget
Long TTLHigher hit ratio, less origin trafficSlower updates, more reliance on purging
Short TTLFresher contentMore trips to the origin and a lower hit ratio
Origin shieldFewer origin fetchesOne more layer, and a small extra delay on a miss
HybridGood fit for both kinds of fileTwo ways of working to keep in mind

10Common Problems and Mistakes

Common mistakes

  1. Pushing everything. Storing millions of rarely used files costs money and gives no benefit over pull.
  2. Forgetting to push the new version. Users keep getting the old file, and nothing is reported as an error.
  3. A pull CDN with no cache headers. Some CDNs then use a default, or refuse to cache. The hit ratio is poor and the origin gets everything.
  4. Long TTL and no versioned names. A change cannot reach users for hours, unless you purge.
  5. Relying on a purge for every release. It is manual, can be slow to spread, and is easy to forget.
  6. Caching personal pages. One user's data can be served to another.
  7. A cold launch on pull. A huge launch with empty edges sends a burst of misses to a small origin.
  8. An origin that cannot take the fetches. A pull CDN needs an origin that stays up and is fast enough for misses.

Things to watch

๐Ÿ“‰Low hit ratio
Look at cache headers, query strings in URLs and very short TTLs. These often stop the edge from reusing files.
๐ŸŒSlow in one region
That region may have a cold edge, or a long trip to the origin. Consider a shield or pre-warming.
๐Ÿ•ฐ๏ธStale content
Check TTLs, whether the new version was pushed, and whether the purge finished everywhere.
๐ŸšจOrigin overload after a purge
Purging everything makes every edge fetch again at once. Purge in a targeted way.

11Real-World Examples

๐ŸŒMost websites
Static assets go through a pull CDN, with long cache lifetimes and hashed file names.
๐ŸŽฌStreaming launches
Providers place popular titles close to viewers ahead of demand, which is a push-like approach.
๐Ÿ“ฆOperating system and app updates
Big updates are distributed from many locations, so launch day does not overload one server.
๐ŸŽฎGame stores
Large game files and patches are pre-positioned and served from nearby edges.
๐Ÿ›๏ธOnline shops
Product images are pulled on demand, with a shield in front of a small image server.
โ˜๏ธCloud storage as origin
Many sites use an object storage bucket as the origin for a pull CDN, so the origin scales on its own.
๐Ÿ“Note
Product features differ: some CDNs call their storage-backed mode "push", others offer preloading, and some do both. Check your provider's documents for what each option really does.
Mini case: a launch-day installer
๐Ÿง‘โ€๐Ÿ’ปReleasebuild the installer
โ†’โ†“push 1 day early
๐Ÿ“All edgesinstaller already there
โ†’โ†“launch day
๐Ÿ‘ฅMillions of usersall edge hits
You CDN Users
Pushed ahead of time, with a pull CDN left in place for everything else on the site.

12Related Topics to Read Next

CDNโ†’

The basics: what edges are, and why a CDN makes sites fast.

HTTP Caching (Cache-Control, ETag)โ†’

The headers a pull CDN follows to decide how long to keep a file.

Cache Invalidationโ†’

How to remove or refresh old copies after a change.

Cache Warmingโ†’

Filling caches before users arrive, the same idea as pre-warming a pull CDN.

Object Storageโ†’

A very common origin for a CDN, and a place to keep pushed files.

Anycast Routingโ†’

One way users are sent to a nearby edge.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”Pull: edge fetches from the origin on the first request, then keeps it for the TTL.
  • โœ”Push: you upload ahead of time and manage updates and clean-up.
  • โœ”Pull cost: the first user at each edge is slower. The origin must handle misses.
  • โœ”Push cost: upload work and storage for files that may never be asked for.
  • โœ”Use pull for: many files, unpredictable demand. Push for: a few big, known files.
  • โœ”Updates: use versioned file names, so a change is a new URL and needs no purge.
  • โœ”Helpers: an origin shield cuts origin load. Pre-warming avoids a cold start.
  • โœ”One line: โ€œPull fills the edge when someone asks; push fills it when you decide.โ€
โ† Previous
Cache Penetration and Cache Avalanche
Next โ†’
Common Database Types