Build a CDN (13 scenes)
Scene 02 · An edge near the user — hit and miss
An edge cache absorbs the second request in each region; the first still pays the full RTT, and edges don't share content across regions.
Previously

One origin can't be close to everyone — so we put a copy of the content near each user, and now the question is whether having a copy nearby is enough to make every request fast.

Scene 02
An edge near the user — hit and miss
Diagram
Three regional servers (Sydney, Frankfurt, São Paulo) sit between the users and the single origin from scene 1, each with one cache slot for /logo.png — gray means empty, green means a copy is sitting there ready to serve. **edge** — a server near users that caches origin responses, so most requests never reach origin. **cache hit** — a request the edge serves from its local copy without contacting origin. **cache miss** — a request the edge has to forward to origin because its local copy is missing. The HIT and MISS counters on each edge tally the two outcomes; the origin RPS gauge on the right is the one number every CDN lever ultimately moves.
WITH CDNORIGINus-eastEDGESydney(empty)HIT 0MISS 0usruser · SydneyEDGEFrankfurt(empty)HIT 0MISS 0usruser · Frankf…EDGESão Paulo(empty)HIT 0MISS 0usruser · São Pa…ORIGIN RPS0 / 12per-region p50 — short bars mean the edge is doing its jobSydney0 µsFrankfurt0 µsSão Paulo0 µsfirst request in each region pays the long ocean trip; every subsequent request in that region is a local HIT.
Each region's first request goes all the way to origin (long orange arrow) and the local cache slot fills green. Subsequent requests in the same region come back fast from the edge — the latency strip drops from ~200 ms to ~10 ms.
Implementation
Edge.handle
the request handler running on every edge POP
1def handle(req):
2 key = cacheKey(req) # URL + Vary axes
3 entry = self.cache.lookup(key)
4 if entry is not None:
5 return entry.body # HIT — served locally
6 # MISS — origin is the only source
7 body = origin.fetch(req.url)
8 self.cache.store(key, body)
9 return body
EdgeCache.lookup
the cache slot is per-edge — no peer consultation
1def lookup(key):
2 # self.slots lives in THIS POP's RAM/SSD only.
3 # Sibling edges in other regions are never queried.
4 entry = self.slots.get(key)
5 if entry is None:
6 return None # caller must go to origin
7 return entry
8
9def store(key, body):
10 self.slots[key] = Entry(body)