Why a CDN makes a request faster
A new HTTPS request needs 3 round trips before the first byte arrives, and each round trip costs time in proportion to distance. A CDN moves those round trips onto the short path to a nearby edge server. The long trip to the origin happens once on a cache miss, and not at all on a hit.
Three machines, two distances
Start with no CDN
What a new request costs: a new connection needs 3 round trips (TCP, TLS 1.3, then the request itself). Light in fiber goes 100 km and back in about 1 ms. The origin takes about 20 ms to answer. Without a CDN, the client talks to the origin directly; this page takes that distance to be the same as the edge-to-origin distance.
Three paths for the same request
With a CDN, the handshakes and the request go to the edge. On a miss, the edge asks the origin over a connection it keeps open: one long round trip, with no new handshakes. Move the edge closer or farther, and watch the hit and miss rows.
How, why, and how it is built
Level 2 · howThe steps of one request
- DNS sends the client to a nearby edge server.
- The client opens TCP and TLS with the edge: two round trips on the short path.
- The client sends the request: one more short round trip.
- On a hit, the edge answers from its cache. On a miss, the edge asks the origin over a connection it keeps open, caches the answer for its TTL, and replies.
Level 3 · whyRound trips multiply distance
Each round trip costs about 1 ms per 100 km of fiber. A new request costs 3 round trips, so its time grows with 3 × distance. The CDN keeps those 3 round trips on the short path.
Level 4 · implementationWhat makes a hit
The edge stores a response under a cache key, usually the URL plus selected headers. Cache-Control: max-age from the origin sets the TTL. Many CDNs route clients to the nearest edge with anycast or DNS steering. Responses that differ per user, such as account pages, are usually not cached, so every such request is a miss.
What the numbers leave out
About two thirds of its vacuum speed, so 100 km of fiber costs about 1 ms per round trip.
Real routes are longer than the straight line, so real round trips take longer.
1 ms at the edge and 20 ms at the origin are round numbers, not measurements.
A request on a connection that is already open (keep-alive, HTTP/2) needs 1 round trip, not 3. TLS 1.3 resumption can also save a round trip.
So the no-CDN time depends only on the edge-to-origin distance. DNS and bandwidth are left out; large files also depend on bandwidth.
Three facts
- A new HTTPS request needs 3 round trips, and each one costs time in proportion to distance.
- A CDN puts those round trips on the short path to a nearby edge. A faster origin would save only its 20 ms of processing.
- A miss adds one long round trip on an open connection, so it is still faster than no CDN, as long as the edge is less than about two thirds as far as the origin. With the edge 2,000 km away and the origin 1,000 km, a miss takes 91 ms against 50 ms with no CDN.