
An origin can run quietly for hours, then experience a sharp rise in connections and latency when a popular cached object expires. If the burst follows cache expiry, invalidation, or a deployment, investigate whether concurrent requests are independently fetching the same content.
A cache stampede can affect one hot object or many objects that expire together. The remedy depends on the affected cache keys, cache tiers, and actual origin requests. A site-wide average hit ratio can hide a brief but damaging spike.
Align the burst with objects and expiry events
Capture timestamps with time zones, affected URLs, cache status, request IDs, origin request counts, and response durations. Use a monitoring interval short enough to show the burst. Separate visitor traffic from warming jobs and probes.
If requests converge on one cache key, inspect concurrent fills after that object's expiry. If many paths expire together, check shared TTLs, bulk invalidations, and deployment actions. Constantly changing query parameters or cookie-based bypasses suggest a fragmented cache key or uncacheable traffic instead; increasing TTL will not fix those causes.
An edge MISS does not necessarily reach the final origin. An upper cache may serve it. Correlate edge, upper-tier, and origin logs rather than adding MISS counts from different layers together.
Request collapsing depends on a matching cache key
Request collapsing lets concurrent cache misses for the same object share a fetch. Provider implementations differ in their supported tiers, geographic scope, waiting behavior, and timeout handling.
Compare the hostname, path, query parameters, and headers included in the effective cache key. Unique tracking parameters that participate in the key create separate entries. Normalize only inputs confirmed not to affect the response. Keep tenant, authentication, and personalization boundaries intact.
Do not assume collapsing means exactly one origin request worldwide. Independent locations may each fill a cache, and an upper tier may or may not collapse those requests again. Slow fills can also exceed waiting limits and allow additional requests upstream. Check the provider's documented behavior and verify it in origin logs.
Decide whether stale responses are acceptable
For public assets or pages that tolerate bounded staleness, evaluate stale-while-revalidate. A supporting cache can reuse an existing stale response during the allowed window while updating it. This requires an eligible stored response: the first request to a new path has no old body to reuse.
Balances, authorization decisions, inventory-sensitive results, and personalized pages need their own freshness and isolation requirements. Review other Cache-Control directives, platform overrides, and actual support. Adding a response directive at the origin does not establish that every downstream cache implements the intended behavior.
stale-if-error addresses reuse when fetching or validating fails. It differs from serving stale content during normal background revalidation. Bound the resource scope and staleness window, define how to withdraw the policy, and verify compatibility with application requirements.
An Nginx cache lock protects its own cache layer
If you operate an Nginx cache in front of the application, review proxy_cache_lock, proxy_cache_background_update, and proxy_cache_use_stale. The following is an illustrative fragment for an existing cache configuration, not a complete server configuration:
# Apply only to public resources confirmed safe for shared caching. # Requires an existing proxy_cache_path, cache key, and proxy_pass setup. proxy_cache_lock on; proxy_cache_background_update on; proxy_cache_use_stale updating;
Cache locking coordinates creation of a new entry for the same key in the relevant shared cache zone. Check lock timeout, lock age, and support in the installed version. Background updating needs permission to serve stale content during updating for the intended behavior. These directives do not coordinate independent caches on separate servers or make private responses safe to share.
Save the original configuration, run nginx -t, and roll out to a small set of public resources. A passing syntax check does not validate cache correctness. Inspect returned bodies, cache status, and origin logs; restore the original configuration through the normal reload process if behavior is wrong.
Spread expiry and avoid unnecessary global purges
Group resources by update frequency and popularity instead of giving every object the same expiry schedule. Where supported, bounded TTL jitter can spread refreshes within the application's freshness limits. Do not introduce arbitrary variation across the whole site without checking those limits.
Content-fingerprinted paths suit static assets: deploy the new files, update references, and retain old files through the transition and rollback window. Design HTML, API, and static-asset policies separately.
Limit warming by object count, rate, and location. Confirm the origin is ready before expanding a warming job. Aggressive warming can itself produce the load spike you are trying to avoid.
Invalidate affected URLs or supported tags where possible. A global purge removes many usable entries at once and can send otherwise stable traffic back to the origin. It does not replace concurrency control.
Verify a complete expiry cycle with bounded traffic
Use a test environment or isolated public test path. Populate the cache, wait for its freshness lifetime to end, then apply bounded concurrency and observe the fill. Avoid deliberately stressing a production hot object or repeatedly invalidating it.
Measure the body version, status codes, latency, final-origin request count, origin concurrency, and errors. If stale responses are allowed, record their actual age and duration against the business limit. Include first visits with no stored response, failed updates, and simultaneous requests from multiple locations.
If duplicate origin requests fall but client waiting time rises, investigate lock waits, origin processing time, and background update policy. Accept the change when origin load is controlled and content meets freshness requirements, rather than relying only on a higher hit ratio.
References
The configuration is illustrative and has not been executed in your production environment. Verify CDN request-collapsing scope and stale-response support against the deployed platform documentation and configuration.