Core Concepts
Content Delivery Network (CDN)
Serve reusable HTTP responses close to readers while keeping freshness and private data under control.
A content delivery network (CDN) keeps copies of public assets at servers in several locations. These servers are called edges. When an edge close to the browser has a fresh copy, it can serve the request without a trip to the origin, the service that owns the response.
Follow a request through a cache miss and hit
Maya's browser in Lisbon requests /guide.8bf.css from a site whose origin is in Frankfurt. The Lisbon edge looks for a reusable response. On a miss, it fetches the stylesheet from the origin or an upstream cache that has it. The edge sends the response back and stores it if the response's HTTP policy permits. The next browser can get a hit from that edge while the stored response is fresh. HTTP cache overview and storage rules
An edge that has never seen this asset will have a miss of its own. Popular assets tend to stay warm where they are requested. Small audiences, many cache keys, or a purge can send a larger share of requests to the origin. Estimate origin work by response size and by miss load under bursts, and measure how long the edge and origin each take.
Give matching requests the right response
A cache key identifies the response a request can reuse. HTTP caches start with the method and requested URL. The CDN may let you include other request fields. For example, Accept-Encoding tells the origin which compression formats a browser accepts. If the origin chooses the response variant using that header, it sends Vary: Accept-Encoding so the cache can select a matching variant for the next request. Cache key and Vary
The stylesheet path contains a short hash generated from the file's contents. Publish the next build at a new path and update the page to point there. A browser that still has the old HTML can continue asking for the old stylesheet. Keep the older asset available until those references age out. Updating the stylesheet at a fixed URL would require an expiry or invalidation policy for every copy.
Keep dimensions such as campaign parameters only if they change the response or enforce a product boundary. Custom key rules can lower hit rate by creating many copies. Removing a meaningful dimension can make one request receive another request's data. Make the shared response policy explicit before broadening reuse.
Revalidate a stale public response
Suppose the public /help.json is at a stable URL. Its origin sends Cache-Control: public, max-age=60, s-maxage=300 and ETag: "help-v7". The ETag identifies this version of the response. A browser can reuse it while its estimated age is under 60 seconds. The shared edge cache can reuse it while that age is under 300 seconds. If the browser receives Age: 45, it has at most 15 seconds of freshness left. HTTP freshness and shared cache directives
When a request arrives after the stored response becomes stale, the edge can send If-None-Match: "help-v7" to the origin. If the content is unchanged, the origin can answer with 304 Not Modified and no body. The edge updates the stored metadata and sends the saved body to the browser that made a normal GET. If the help content changed, the origin returns 200 with the new body and tag. HTTP cache validation
If requests for the same variant arrive together, the edge can combine their upstream fetch or validation where all of those requests can reuse the outcome. During an origin outage, stale delivery requires compatible response directives and an explicit allowed policy. In the example, s-maxage requires successful validation before the shared cache reuses the stale response. For data that can tolerate old content, choose a compatible cache policy deliberately. Purging a CDN copy can prompt an early fetch, but independent browser caches may still hold their copy. HTTP stale response rules
Keep account responses out of the shared cache
Two signed-in accounts, A17 and A18, request the same /account path. Each response contains data only its account can see. Set Cache-Control: private, no-store and configure the edge to honor that policy. The private directive forbids shared storage. The no-store directive also forbids browser caches from storing the response. HTTP cache control
In this example, the edge forwards every account request. The origin verifies the session cookie or token and checks which account data the caller may read. Confirm that the CDN forwards the credentials the origin needs. For public files, an application can also restrict how the origin is reached. For example, an S3 bucket can be private and grant read access to a specific CloudFront distribution. CloudFront restricted S3 origin example · HTTP storing responses to authenticated requests
Decide which requests need the origin
The URL Shortener serves many repeated requests that resolve the same link. An edge could reduce latency by caching a redirect with an explicit freshness policy. The walkthrough sends Cache-Control: no-store so each visit reaches the redirect service and can be counted. If you cache redirects at the edge, decide where to count those hits. A service that also supports link changes or moderation must decide how quickly a changed destination or blocked link stops being served from the cache.
Read-only public assets make an easier starting point. Add the edge for assets whose content, cache key, access policy, and freshness rules you can state. Then measure the latency gain and origin load before expanding shared caching to other routes.
See also
- Request Path - follow a request from DNS through the edge to the application.
- Caching - distinguish copies from their source and plan refills and stale data.
- Object Storage (S3) - decide where the file bytes live before an edge serves a copy.
Used in
- URL Shortener - see why the redirect service handles each visit so it can attempt to record the click. This article uses shared redirect caching as a design comparison.
Done reading? Mark it so it sticks in your dashboard.