Upload files to the CDN yourself, or let it fetch them from your server on the first request?
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.
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.
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.
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 (origin pull) | Push | |
|---|---|---|
| Who fills the edge | The edge, on the first request | You, ahead of time |
| First user at an edge | Waits for an origin fetch | Served at once |
| Set-up effort | Low: point the CDN at your origin | Higher: an upload step and file management |
| Origin needs to be up | Yes, whenever a copy is missing or expired | Only while you upload |
| Updating a file | Wait for the TTL, purge, or use a new URL | Upload the new version yourself |
| Storage on the CDN | Only files that were asked for | Everything you push, used or not |
| Best for | Many files, unpredictable demand | A few big files, known in advance |
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:
Cache-Control: public, max-age=31536000, immutable ETag: "9f3c1a" Content-Type: text/css
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.
Cache-Control: private or no-store for it, or the edge may serve it to the next user.| Term | Meaning in easy words |
|---|---|
| Origin | Your own server, where the original files live |
| Edge location | A 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 CDN | You upload files to the CDN yourself, ahead of time |
| Cache hit | The edge already has a fresh copy and answers at once |
| Cache miss | The edge has no usable copy, so it must go to the origin |
| TTL | How long an edge may reuse a copy before it must check again |
| Hit ratio | The share of requests answered by the edge without going to the origin |
| Purge / invalidate | Tell the CDN to throw away a file, so the next request fetches a new one |
| Origin shield | An extra cache layer between the edges and the origin, to reduce origin load |
| Pre-warming | Requesting files ahead of time so the first real users get hits |
| Choice | We gain | We lose |
|---|---|---|
| Pull | Little effort and lazy filling | A slow first request at each edge, and a dependency on the origin |
| Push | Fast first request and full control | Upload work and storage cost, and a process you must not forget |
| Long TTL | Higher hit ratio, less origin traffic | Slower updates, more reliance on purging |
| Short TTL | Fresher content | More trips to the origin and a lower hit ratio |
| Origin shield | Fewer origin fetches | One more layer, and a small extra delay on a miss |
| Hybrid | Good fit for both kinds of file | Two ways of working to keep in mind |