Why a CDN
Without help, every visitor fetches the website from its origin server, the site's own computer. If it is far away, each round trip is slow, and the origin must answer every visitor in the world by itself.
A CDN, a content delivery network, runs edge servers in many places. Each keeps copies of the site's files, so a visitor can be answered by a nearby edge instead of the faraway origin.
Finding a nearby edge
One way to steer: the CDN's DNS server gives different answers in different places. Your lookup for www.example.com gets site A's own address, 192.0.2.10. Your friend's lookup would get site C's.
The other way is anycast. All three sites use the same address, 203.0.113.50. Each one announces the same block, 203.0.113.0/24, with BGP, the protocol networks use to tell each other which addresses they can reach.
Your provider's router hears all three announcements. It picks the shortest path, here to site A, so your packets for 203.0.113.50 go there. Nobody picked a site for you: normal routing did.
Your friend lives in another city. Her packets for the same address, 203.0.113.50, reach site C, the nearest site to her. One address, a different server for each place: that is anycast.
Hits, misses and max-age
You ask site A for /logo.png, but it has no copy yet. That is a cache miss. Site A fetches the file from the origin, keeps a copy, and sends it to you. This first time is slower.
You load the page again, or a neighbour does. Site A already has the file: a cache hit. It answers straight away, and the origin is not asked at all, so it does far less work.
The origin said max-age=3600: the copy stays fresh for 3600 seconds, one hour. Site A counts its age. Once the age reaches 3600, the copy is stale and must be checked before it is used again.
Site A asks the origin: has it changed since version "v7"? It has not, so the origin answers 304 Not Modified, with no file attached. The copy is fresh for another hour.
When a site fails
If site C fails, it stops announcing 203.0.113.0/24. Routers drop that path and use the next nearest, site B. Your friend's packets go there, to the same address, with nothing changed on her side.
The messages, step by step
;; step 1/11 · far ;; you → origin GET /logo.png Host: www.example.com you → 198.51.100.20 (the origin) round trip ≈ 180 ms (illustrative: far away, many hops) a page with 40 files may need many round trips and every request in the world lands on this one server
Illustrative numbers: round trips of 180 ms to the origin and 12 ms to a nearby edge, a DNS TTL of 60 s and a max-age of 3600 s. Real values depend on the site and the CDN. 203.0.113.0/24, 203.0.113.50, 198.51.100.20 and the site addresses 192.0.2.10, 192.0.2.20, 192.0.2.30 are RFC 5737 documentation addresses; AS64496 and AS64500 to AS64502 are RFC 5398 documentation AS numbers. www.example.com is reserved by RFC 2606.