CDN Basics Cheat Sheet

Content Delivery Networks: edge caching strategies, cache invalidation and purging, origin shield, CDN security features, and common CDN providers.

Last Updated: May 1, 2025

How CDNs Work

ItemDescription
Edge servers (PoPs)Distributed servers near end users — serve cached content locally
Origin serverYour actual server — CDN fetches from here on cache miss
Cache hitContent served from edge (fast — sub-10ms for static)
Cache missEdge fetches from origin, caches result, serves to user
Time To Live (TTL)How long content stays cached (Cache-Control: max-age header)
Origin shieldExtra cache layer between edge and origin — reduces origin load

Cache Control Headers

ItemDescription
Cache-Control: max-age=3600Cache for 1 hour (browser + CDN)
Cache-Control: s-maxage=86400Override max-age for shared caches ONLY (CDN)
Cache-Control: publicAllow caching by CDN and browsers
Cache-Control: privateBrowser-only caching (NOT CDN) — user-specific content
Cache-Control: no-storeNever cache anywhere (banking, sensitive data)
Surrogate-Control: max-age=600CDN-specific TTL (Fastly/Akamai)
ETag / If-None-MatchConditional request — only send body if changed (304)

Cache Invalidation & Purging

ItemDescription
Purge by URLPurge a specific URL from all edge caches
Purge by prefixPurge all URLs matching /images/* (wildcard purge)
Surrogate keysTag content with keys; purge all tagged content at once
Soft purgeMark as stale — serve stale while revalidating (stale-while-revalidate)
Instant purgeImmediate removal (Cloudflare, Fastly — under 1 second)
Versioned URLsRename assets (app.v2.js) — no purge needed, new URL = cache miss

CDN Security Features

ItemDescription
DDoS protectionAbsorb volumetric attacks at edge (Cloudflare, Akamai)
WAFWeb Application Firewall — block SQLi, XSS at edge
Bot managementDetect and block malicious bots, allow good bots
Token authenticationSigned URLs/expiring tokens for protected content
Origin IP hidingOnly CDN IPs visible — origin stays hidden from attackers
Pro Tip: Set long Cache-Control max-age for versioned assets (app.abc123.js). Use surrogate keys for granular cache invalidation across many URLs at once.