A CDN can keep cached pages available during an origin failure and reduce the traffic your application has to serve. The result depends on which responses can be reused, how stale they may become, and what happens when a request needs the origin. A working homepage says little about whether checkout still works.
This tutorial uses CloudFront for concrete behavior. Other CDNs have different defaults and failure rules. Check those rules before treating a cache as part of your recovery plan.
What a CDN serves from cache
An edge cache looks up a request using a cache key. If it has a reusable, fresh response, it can answer without an origin round trip. A missing object requires a fetch. An expired object may need validation, which still creates origin work even when the origin replies that the content has not changed.
The key must distinguish responses that differ. If a query parameter selects a language or a product variant, dropping it from the key can serve the wrong content. A tracking parameter that leaves the response unchanged can usually be excluded after checking application behavior. Including unnecessary values creates more separate objects to populate. AWS explains this tradeoff in its cache-key documentation.
Check what changes the response
CloudFront has separate cache and origin request policies. Values in the cache key are sent to the origin. An origin request policy can send additional values without including them in that key. Forwarding a session cookie therefore does not, by itself, isolate the cached response for that session.
Suppose a staging catalog uses a currency cookie. The origin returns dollar prices for one value and euro prices for another. If that cookie is forwarded but excluded from the key, both requests can reuse whichever cacheable response arrived first. This is a hypothetical configuration error. Check the application response and both policies together.
Use this worksheet for each route before enabling shared caching. The entries describe intended designs, not CloudFront defaults.
| Input | Response changes? | Cache treatment |
|---|---|---|
| Language | Public text changes | Include the selected variant. |
| Tracking tag | No content change | Omit after checking behavior. |
| Session | Account data changes | Disable shared caching. |
| CORS origin | Allowed origin changes | Key the allowed variant or disable caching. |
For public language variants, check the configured header or query parameter explicitly. A Vary response header alone is not a substitute for reviewing CloudFront's cache policy. AWS documents header-based caching and CORS, including the request headers needed when caching preflight responses. Test a permitted and a rejected browser origin; a cached response must not change that decision.
Cookies also affect response headers. When CloudFront forwards cookies, it can cache origin Set-Cookie headers and replay them on cache hits. AWS documents Cache-Control: no-cache="Set-Cookie" to prevent that field from being cached. That field-specific instruction does not make a personalized body safe for shared caching. Keep account responses on a caching-disabled behavior and verify that authentication still reaches the origin. The cookie documentation also notes that forwarding cookies disables CloudFront's conditional requests using If-Modified-Since and If-None-Match.
Run a two-session cache test
Use a staging distribution and disposable accounts with distinct, harmless markers in their responses. Keep the URL identical between sessions. A unique query string for every request can conceal a collision when that parameter is included in the key.
- Record the matched path behavior, attached policies and origin response headers. Use a fresh test path or invalidate the test object and wait for completion. Keep browser caches empty at the start.
- Request the route as account A, then repeat it as A. Save the response body, status, cache headers and any cookies set by the response.
- Request the same route as account B and as a signed-out visitor, using separate browser profiles or cookie jars. Neither should receive A's marker or session cookie. Check redirects and error responses as well as successful pages.
- Clear the test object's cached state and reverse the order. Then repeat for each public language or currency variant that the route supports.
Compare the results with origin logs and the expected policy. For a route intended to bypass caching, confirm each request reaches the application and gets the right authorization decision. For a public variant intended to be cached, confirm reuse within that variant and separation between variants. Headers such as Age help explain a response's cache history; they cannot prove that another account got the right content. Keep credentials out of shared test reports.
Count the traffic that still reaches the application
For a first capacity estimate, separate reusable public responses from requests that must reach the application. Use an origin request count to confirm the estimate; a viewer-facing hit ratio can conceal work elsewhere in the cache hierarchy.
Consider a hypothetical workload of 1,000 requests per second: 800 public-object requests and 200 uncached application requests. Assume each request that needs the origin produces one origin request, with no retries, validation traffic or request collapsing. This is arithmetic for planning, not a measured CDN benchmark.
| Public cache hits | Public misses/s | Total origin requests/s |
|---|---|---|
| 95% | 40 | 240 |
| 50% | 400 | 600 |
| 0% | 800 | 1,000 |
The 200 uncached requests remain in every row. They may also cost much more CPU or database time than serving a static file. Size and test the application using its actual request mix. A high image hit ratio does not establish checkout capacity.
Cold caches, a broad purge or a change that creates many new keys can increase origin traffic. CloudFront's request collapsing reduces simultaneous fetches for the same key at an edge location. Different keys still produce separate requests, and disabling caching can disable collapsing too. Do not assume one origin fetch serves the whole network.
An additional shared cache can reduce duplicate origin fetches across locations. CloudFront Origin Shield provides that layer. A shield cache and a secondary origin have different jobs: the shield reduces fetches; a secondary origin must be able to serve the application when the primary cannot.
Set an explicit freshness policy
Choose policy by response type. Public documentation can often tolerate delayed updates. Account pages, authorization decisions and current inventory need their own rules.
Under HTTP caching rules, private prohibits storage by shared caches; no-store prohibits storage by caches; and no-cache requires successful validation before reuse. It does not mean the response cannot be stored. max-age sets a freshness lifetime, while s-maxage applies to shared caches and overrides max-age there. A Set-Cookie header alone does not make a response uncacheable.
Check the CDN policy as well as the response. CloudFront warns that a positive minimum TTL can override private, no-store and no-cache. Use a caching-disabled behavior for routes that must never be cached, and test with separate accounts. Its expiration documentation also explains how maximum TTL limits stale serving. A TTL is not a promise that the object stays resident: an infrequently used object can be evicted earlier.
Stale content has two different uses
stale-while-revalidate permits an expired response to be served while the cache attempts an update in the background. stale-if-error permits an expired response to be reused when an eligible error occurs. These are separate controls, defined in RFC 5861. Neither creates a cached copy where none exists.
This hypothetical policy allows 60 seconds of freshness, then 30 seconds for background updates or 300 seconds for eligible errors. It assumes a retained object, supported controls and no conflicting policy. These are expected behaviors, not test results.
| Cache state | Expected handling |
|---|---|
| Fresh | Serve the stored response. |
| Stale by 20 seconds | May serve it while attempting an update. |
| Stale by 120 seconds, eligible origin error | May serve the stored response under the error allowance. |
| Stale by more than 300 seconds | These allowances no longer permit reuse. |
| No stored copy | Fetch or fail; there is no stale response to serve. |
Both allowances start at expiry. Successful validation changes freshness. Agree on acceptable age with the content owner; an old permission decision can cause harm.
Cached errors can outlast the outage
An origin recovering does not immediately replace every error already stored at the edge. CloudFront normally caches eligible errors for ten seconds, with an Error Caching Minimum TTL configurable by status code. Origin freshness headers can extend that duration, subject to the behavior's maximum TTL. A short error TTL increases retry traffic; a long one can delay visible recovery.
Check the error code as well as the header. AWS currently honors no-store, no-cache and private for error responses with status 404, 410, 414 or 501, but ignores those directives for other cacheable error codes and uses the error minimum TTL. For S3 origins with caching enabled, a configured zero error minimum still has a one-second floor. These are CloudFront rules, described in its error-cache documentation.
Add a new test object with no stored successful response to the outage drill. Make it fail, restore it, and measure when the public path serves the repaired response. That isolates cached-error recovery from the stale-success case above. If an error persists, invalidate the affected object after fixing the origin and verify the result.
Plan the invalidation's scope. CloudFront removes all header and cookie variants for an invalidated path, while cached query-string variants need the appropriate paths or a wildcard. Follow AWS's invalidation rules and keep the purge bounded. Removing many cached objects at once can create the cold-cache load shown in the capacity table.
Test the exact origin failover rule
CloudFront origin groups use a primary and secondary origin. With default origin priority, CloudFront tries the primary on a cache miss and uses the secondary when the configured failure conditions apply. Subsequent misses try the primary again. This differs from permanently switching traffic after a background health check.
Failover applies to GET, HEAD and OPTIONS; OPTIONS must also be enabled as a cached method. It does not fail over POST or PUT. A catalog read succeeding at the secondary therefore says nothing about whether an order submission can recover.
Connection attempts and timeouts affect the wait before fallback. For connection failure, AWS requires 503 among the failover codes; for an origin response timeout, it requires 504. Test these separately from each selected HTTP error. An application that returns a broken page with status 200 will not trigger status-based failover. The secondary needs the required content, configuration and capacity, plus a defined approach to data consistency. See the recovery-path guide before relying on replicated application state.
Anycast does not prove application health
Anycast advertises an address from multiple locations. Routing selects a path according to network policy and topology, which need not lead to the geographically closest site. Moving traffic away from a failed service requires the operator to connect service health to routing or another traffic-steering mechanism. RFC 4786 describes that coupling and the risks of route changes.
A reachable edge can still serve errors from a broken origin. Keep regional observations separate, record the responding location when available, and investigate disagreements. Multi-region checks cover more paths, but do not inspect every edge or every user's route.
Prove which layer each check reaches
Use a normal public URL check to test the path visitors use, including DNS, TLS and the CDN. Verify expected content as well as status. Use a deliberately uncached application check to test an origin-dependent operation through that path. Confirm it reaches the application in origin logs.
A random query string only changes the cache lookup if the cache key includes it. A viewer's Cache-Control: no-cache header does not force CloudFront to fetch from the origin. Neither is a substitute for a verified uncached behavior.
For a separate origin check, configure a route to the origin with the correct hostname and TLS validation, plus explicit access controls. Adding a secret header to the public CDN URL does not change its network destination. AWS documents restricted origin access, including private origins and protected public load balancers. Keep any direct monitoring exception narrow, and treat secret header values as credentials. If the monitor cannot reach or authenticate to the origin, run the check from a permitted network.
Before a launch, run a bounded staging drill:
- Record the cache behavior, key and TTLs. Warm a public test object and confirm which requests reach origin logs.
- Make that test origin return an eligible error. Compare a fresh hit, an expired stored object and a new object that has never been cached. Set a stop time and keep production traffic outside the test.
- Exercise the secondary with each intended read method. Test writes through the application's own recovery path. Check response content, latency and origin load.
- Restore the origin. Confirm fresh content returns, uncached operations succeed and cached errors clear under the configured policy. Repeat the session-isolation test after any cache-policy change. Record what failed and who will fix it.
Keep the public-path check running through the drill. We recommend comparing its result with the uncached check and origin logs before calling the service recovered.