What is a CDN and how does it reduce latency
CDN edge nodes, Points of Presence, origin server, cache-control for CDN, CDN invalidation, dynamic vs static content, CDN for API responses
What is a CDN and how does it reduce latency
The Physics Problem
Light travels through fiber at roughly 200,000 km/s. A request from Mumbai to a server in Virginia adds ~150ms of raw latency before any processing. CDNs place cache nodes geographically close to users, eliminating most of that latency for cacheable content.
How It Works
The first request to an edge node misses, fetches from origin, and caches locally. Subsequent users in that region are served from the edge — often under 5ms. The CDN caches based on the Cache-Control headers your origin sets:
# s-maxage overrides max-age for shared caches (CDNs)
# while keeping browser TTL at max-age value
Cache-Control: public, max-age=3600, s-maxage=86400CDN Invalidation
Purging CDN cache propagates across all edge nodes in seconds to minutes. The professional solution is content-addressed URLs: when an asset changes, its URL changes via a hash in the filename. The old URL keeps serving cached content; the new URL is a cold miss that repopulates. For API responses, use short TTLs or stale-while-revalidate rather than manual purge workflows.
