Concept Simulators / Speed and waiting
CDN and edge caching
Hit ratio, freshness, and the surge on the origin when a purge empties the caches.
On the roadmap:Beginner · step 2: How the web works
Settings
At 60 seconds, purge
Answered at the edge
91%
Average response
27 ms
Slowest 5%
145 ms
Origin load (steady)
47/s
91% of requests are answered at the edge, so the origin handles about 47 a second instead of 600. The average response is 27 ms, against 130 ms with no CDN.
Requests reaching the origin each second
requests per second
In plain words
A CDN keeps copies of popular content in many places near users. A request that finds its object at a nearby edge is answered at once, and only a miss travels to the origin. The hit ratio, how long objects stay fresh, and what happens when you purge decide how much it helps.
Why it matters
A CDN turns a long trip into a short one for most users, and shields the origin from most of the traffic. But it only works while the cache is warm. Here you can see the hit ratio change with cache size and freshness, and what happens to the origin when a purge empties the caches at the worst moment.
How real systems do it
The simulation is a simplified model. Here is what production systems add or do.
- Content is cached for as long as its Cache-Control header says (max-age for browsers, s-maxage for shared caches). stale-while-revalidate lets a cache serve an old copy while it fetches a new one.
- Request coalescing, also called request collapsing, is a standard feature in Varnish and Fastly: many simultaneous misses for the same object become a single request to the origin.
- Many CDNs add a middle layer, such as Cloudflare's Tiered Cache, so a miss at one edge is answered by a regional cache and not by the origin.
- Netflix does not wait for a miss. It copies popular titles to its Open Connect boxes during off-peak hours, so they are already close when people press play.
Study: CDN and edge caching
Once you have played with it, learn the same idea from people who build these systems. Watch first for the picture, then read for the detail.
4 minWhat Is A CDN? How Does It Work?
ByteByteGo · 386K views



