CDN and edge caching

A CDN (Content Delivery Network) is a set of edge servers (POPs) close to users. It caches static assets (and often API responses) at the edge so requests are served from a nearby node instead of the origin, reducing latency and load on the origin.

Request path with CDN

flowchart LR U[User] --> Edge[Edge POP] Edge --> |Cache hit| U Edge --> |Cache miss| Origin[Origin server] Origin --> Edge Edge --> |Store & return| U

What lives at the edge

Content typeTypical use
Static assetsJS, CSS, images, fonts — long TTL
API responsesCacheable GET with Cache-Control; short TTL or key by user
Whole pagesStatic or ISR pages

Cache-Control at edge

Origin sends Cache-Control: public, max-age=3600 (and optionally s-maxage for shared/CDN). Edge caches and serves for that period; after expiry it revalidates with origin (or serves stale while revalidating).

flowchart TB O[Origin: Cache-Control headers] --> E[Edge cache] E --> |max-age| Serve[Serve from edge] E --> |Expired| Revalidate[Revalidate with origin]

Use a CDN for static content and for cacheable API responses when low latency and offloading origin matter. Invalidate or use short TTL when content must stay fresh.