Skip to main content
← All posts

Part 7: CDN (Content Delivery Network): Edge Caching, Anycast DNS & Origin Shielding

Md. Harun-Or-RoshidNov 5, 20263 min readArticle
Part 7: CDN (Content Delivery Network): Edge Caching, Anycast DNS & Origin Shielding

Lesson Overview & Learning Objectives

Even with optimized application code and database queries, your web application cannot evade the physical laws of nature: the speed of light in fiber optics introduces inescapable latency when users are separated by oceans. A user in Sydney requesting assets from an origin server in Frankfurt experiences ~300ms of pure round-trip network delay. Content Delivery Networks (CDNs) eliminate this penalty by distributing hundreds of caching proxy servers (Points of Presence) around the planet. In this article, we examine Anycast routing, cache hit/miss flows, origin shielding, and HTTP cache headers.

1. How Anycast BGP Routes Users to the Closest PoP

How does a single domain or IP address direct visitors in London to a London datacenter and visitors in Tokyo to a Tokyo datacenter? Through BGP Anycast:

Under traditional Unicast routing, each IP address belongs to exactly one physical server on the internet. With Anycast, hundreds of edge servers located across the globe advertise the exact same IP prefix via BGP. Core internet routers deliver the user's packet to the topologically closest edge server based on standard shortest AS-Path BGP metrics.

2. Cache Hit vs. Cache Miss & Origin Shielding

⚡ Cache Hit (90% - 98% of Requests)

The requested asset (e.g. app.js, hero.webp) is stored in the local edge PoP's NVMe SSD or memory tier and is still valid within its TTL. The edge immediately returns the response to the user within 5-15 milliseconds, with zero traffic reaching your origin server.

⚠ Cache Miss & Origin Shield

If the asset is missing or expired, the edge proxy must fetch it. Without protection, hundreds of edge PoPs experiencing simultaneous cache misses could trigger a Thundering Herd problem, overloading the origin server. A modern CDN uses an Origin Shield—a centralized caching tier placed in front of your origin datacenter—to consolidate edge misses into a single origin request.

3. Mastering Modern HTTP Caching Headers

Header DirectiveCached ByEngineering Behavior
public, max-age=31536000, immutableBrowser & CDNUsed for content-hashed assets (e.g., bundle.a8f9c1.js). Never revalidates for 1 year.
s-maxage=86400, max-age=0CDN OnlyInstructs public CDN caches to store for 24 hours while forcing end-user browsers to always revalidate.
stale-while-revalidate=60Browser & CDNInstantly serves stale cached content to user while asynchronously fetching fresh content in background.
ETag: "686897696a7c" / If-None-MatchValidationConditional revalidation: if asset has not changed, origin returns 304 Not Modified with empty body.
Share:
Share on X
Share on LinkedIn
Share on Facebook
Share on Reddit
Share on WhatsApp
Share on Telegram
Copy link

Related reading

CDN Architecture: Edge Caching & Anycast DNS | Draftsbook · Draftsbook