Notebook diagram: a CDN edge cache miss fetches from origin on the first request, and later visitors near the same city get a local hit Networking & Traffic Management • Sensei Learning System

The First Visitor Pays So the Next Thousand Do Not

A CDN is a fleet of caches parked in many cities. The interesting question is not the fast case — it is what happens on the first request for an object.

Core Concept

A content delivery network (CDN) is a fleet of caches “edges” parked in many cities, each sitting between your visitors and your origin server. When a request arrives at an edge that has never seen that object, it is a MISS: the edge must fetch it from your origin and only then answer. That first visitor waited longer than if there had been no CDN at all — they paid the trip to the edge plus the edge’s trip to the origin.

Every later visitor near that city computes the same cache key, gets a HIT, and is served locally with no origin trip. So a CDN is not a speed-up. It is a bet: one slow request buys many fast ones. The only number that decides whether the bet pays is the hit ratio — hits divided by all requests.

Key Components

Hit Ratiohits ÷ all requests. The single number that decides whether the CDN bet pays off for a given class of content.
The Cache KeyThe whole design. Two requests share a cached object only if they compute the same key. One extra cookie, user id, or query parameter quietly creates one entry per user — hit ratio near zero.
Origin ShieldingOn a global miss, you do not want 200 edges stampeding the origin for the same object. One designated parent cache absorbs the misses; the other edges fetch from it.
PhysicsLight in fibre covers roughly 200 km per millisecond. A round trip to a server 5,000 km away cannot beat ~50 ms no matter how fast your code is. Distance is the cost nobody can engineer away.

How It Works

  1. Visitor requests an object. The nearest edge cache is empty for it → MISS.
  2. The edge fetches the object from the origin — the slow path: visitor↔edge plus edge↔origin round trips.
  3. The edge stores the object under that request’s cache key and answers the visitor.
  4. Next visitor, same city, same key → HIT: served locally, no origin trip, milliseconds of latency.
  5. When an object is cold everywhere, the origin shield takes the one fetch, so the whole fleet misses the origin once instead of 200 times.

Real-World Applications

PAYS
Static assets — JavaScript, CSS, images, fonts. Thousands of requests, the same key for everyone: high hit ratio, the CDN earns its hop.
LOSES
Personalised dashboards, logged-in feeds, user-keyed API responses. Every request is a unique key, every request is a miss: the CDN adds a hop, a bill, and a second place for bugs to live — in exchange for nothing.
TRAP
“95% hit ratio” while the site feels slow. The hits can all be small static assets while the one render-blocking HTML document misses every time. Group the hit ratio by content type instead of trusting the global figure.
Falsification: put a CDN in front of content that is never requested twice and it makes it slower — not a corner case, but most dynamic applications.

Checkpoint — answer before you move on

  1. Why is the very first request for an object slower than it would be with no CDN? Name the two trips the first visitor pays, and say what the edge stores so the next visitor does not pay them.The miss path: visitor→edge, then edge→origin. The edge stores the object under that request’s cache key.
  2. You add the user’s id as a query parameter so the cache can be “user-aware.” What happens to the hit ratio, and why is the cache key called the whole design?Every user computes a different key → one entry per user → nearly all misses.
  3. Your CDN dashboard reports 95% hit ratio, yet the site feels slow. Give one way that number can hide the problem, and the honest two-step test you would run.Group hits by content type; request the same URL twice from one region, then once from another continent, and compare.