Lab · Building blocks

CDN and edge caching

Users in three regions fetch files through a nearby edge cache. The origin sits in the US. See how popularity, TTL and cache size set the hit rate, what a purge does, and how an origin shield protects the origin.

Try it

Lab time 3.0 s
30 ms90 ms150 msUS, 20 requests/sUS20 requests/sUS edge, hit rate 49%US edgehit rate 49%20/20 filesEurope, 20 requests/sEurope20 requests/sEurope edge, hit rate 62%Europe edgehit rate 62%20/20 filesAsia, 20 requests/sAsia20 requests/sAsia edge, hit rate 61%Asia edgehit rate 61%20/20 filesOrigin (US), holds every fileOrigin (US)holds every file18 fetches/s

The lab is busy, so only some requests are drawn as dots, few enough to follow. The numbers still count every request.

  • US — 20 requests/s — healthy
  • US edge — hit rate 49% — healthy — 20/20 files
  • Europe — 20 requests/s — healthy
  • Europe edge — hit rate 62% — healthy — 20/20 files
  • Asia — 20 requests/s — healthy
  • Asia edge — hit rate 61% — healthy — 20/20 files
  • Origin (US) — holds every file — healthy — 18 fetches/s
  • Request
  • Edge hit
  • Edge miss → origin
  • Answer after a miss
Hit rate
58%
Origin fetches
18/s
Average wait · US
61 ms
Average wait · Europe
73 ms
Average wait · Asia
98 ms
Purges
0

Numbers add up:201 requests = 117 hits + 84 misses; misses = 84 origin fetches + 0 shield hitsThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Files
Popularity

A few files get most requests, as on most websites.

(TTL)
Edges
20 of 60 files

Edge misses go to one shared cache next to the origin first.

By region

RegionHit rateAverage waitFiles cachedTrip to origin
US49%61 ms20 of 2030 ms
Europe62%73 ms20 of 2090 ms
Asia61%98 ms20 of 20150 ms

A miss in Asia costs the most, because Asia is farthest from the origin. Hits cost the same 20 ms everywhere.

Hit rate
0%25%50%75%100%1s2s3s
Show data table
TimeHit rate
1s19%
1s26%
2s43%
2s49%
3s54%
3s58%
Origin fetches per second
012.52537.5501s2s3s
Show data table
TimeOrigin fetches/s
1s42
1s45
2s38
2s21
3s17
3s18

What just happened

  1. 0.0sInfo: Every edge starts empty. Each keeps up to 20 files for 30 s.
What this model simplifies
  • Round trips are fixed and illustrative: 20 ms to the nearby edge, and 30, 90 or 150 ms from each edge to the origin. Real networks vary.
  • Time is slowed so you can watch each request. The share of hits and misses is what matters here.
  • Two misses for the same file at the same moment each go to the origin. Real CDNs often combine them into one fetch.
  • Each region has one edge, and every file has the same size. Real CDNs run hundreds of edges and cache files of very different sizes.
  • A copy counts its TTL from when this cache stored it. A copy from the shield starts a new TTL, so a file can be up to twice the TTL old. Real CDNs pass on the copy's age.
  • Changing the TTL also changes copies already stored. The shield has room for three edges' worth of files, which here is every file.