Explainer · interactive

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.

Level 1 · What it is

Three machines, two distances

client edge origin 300 km 6,000 km short: every handshake long: only on a cache miss
Predict first

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.

The instrument

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.

Go deeper

How, why, and how it is built

Level 2 · how

The steps of one request

  1. DNS sends the client to a nearby edge server.
  2. The client opens TCP and TLS with the edge: two round trips on the short path.
  3. The client sends the request: one more short round trip.
  4. 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 · why

Round 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 · implementation

What 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.

Limits of this model

What the numbers leave out

factLight in fiber is slower than in vacuum.

About two thirds of its vacuum speed, so 100 km of fiber costs about 1 ms per round trip.

assumptionStraight paths.

Real routes are longer than the straight line, so real round trips take longer.

estimateProcessing times.

1 ms at the edge and 20 ms at the origin are round numbers, not measurements.

simplificationA new connection for each request.

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.

assumptionThe origin is as far from the client as from the edge.

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.

Summary

Three facts

  1. A new HTTPS request needs 3 round trips, and each one costs time in proportion to distance.
  2. 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.
  3. 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.