Request collapsing

Also known as: request coalescing

On this page 6

Request collapsing, also called request coalescing, is a caching technique in which a proxy or CDN node that receives many simultaneous requests for the same uncached object sends only one request to the origin and serves the single response to every waiting client. In content delivery across the Internet, it is a primary defense against the thundering herd problem, where a cache miss on popular content would otherwise multiply into thousands of identical origin fetches.

The technique matters most at the moments when caches are weakest: right after a cache purge, when an object expires, or when new content is published and requested by a large audience at once.

How request collapsing merges concurrent cache misses

When the first request for an object misses the cache, the edge node creates a pending fetch entry keyed by the cache key. Every further request with the same key that arrives while the fetch is in progress is placed in a waiting queue instead of triggering its own origin request. When the origin responds, the node stores the object if it is cacheable and fans the response out to all queued clients.

The mechanism depends on an accurate cache key. Two requests collapse only when the node can be certain they would receive the same response, so the key must include every attribute that changes the content, such as the host, path, relevant query parameters and headers listed in the Vary header.

Collapsing also applies to revalidation. When a stale object carries an ETag or Last-Modified validator, the node sends one conditional request, and a 304 Not Modified reply refreshes the cached copy for every waiting client. The benefit therefore covers both full misses and expiry checks, which is where much of the origin traffic on busy sites originates. The size of the saving grows with the number of clients requesting the object within the fetch window, so the effect is strongest for popular, short-lived content such as live scores, manifests for streaming video and news homepages.

The following table summarizes the sequence for one popular object after expiry.

MomentEdge node actionOrigin load
First request missesOpens one origin fetchOne request
Further requests arriveQueue behind the pending fetchNo additional requests
Origin respondsStores object and answers all waitersFetch completes
Later requestsServed directly from cacheNone until expiry
Request flow with collapsing enabled

Collapsing at the edge, the shield and the origin

Request collapsing can occur at several layers, and its effect compounds across tiers. A single edge node collapses requests from its own clients, but a CDN with hundreds of points of presence could still send one request per node. Tiered caching and an origin shield add a second collapsing layer, so all edge misses converge on one intermediate cache that sends a single fetch upstream.

LayerRequests mergedRemaining origin traffic
Single edge serverClients of that serverOne fetch per server
Point of presenceClients across servers in one locationOne fetch per location
Origin shieldMisses from all edge locationsOne fetch per shield region
Origin reverse proxyRequests reaching the origin clusterOne fetch to the application
Where collapsing takes place

Major platforms such as Fastly, Akamai, Cloudflare and Amazon CloudFront implement collapsing natively, and open-source proxies offer it as configuration: Varnish collapses by default, while NGINX uses the proxy_cache_lock directive. The defaults and timeouts differ, so operators should verify the behavior rather than assume it.

Request collapsing protects the origin during a miss, while related techniques avoid or soften the miss itself. In practice, mature content delivery configurations combine them.

TechniqueProblem addressedHow it differs
Request collapsingDuplicate concurrent origin fetchesMerges requests during a miss
Stale-while-revalidateLatency at expiryServes the old copy while refreshing in the background
Stale-if-errorOrigin failuresServes the old copy when the origin returns errors
Origin shieldMany edge locations fetching separatelyAdds a central cache tier
Cache prewarmingCold cache after deploymentFetches objects before users request them
Collapsing and neighboring techniques

The combination of collapsing with stale-while-revalidate is particularly effective: users receive an immediate stale response, and only one background revalidation reaches the origin.

Limits, risks and configuration pitfalls

Collapsing introduces a dependency between unrelated clients, because every waiting request shares the fate of the leading fetch. If the origin is slow, all queued clients wait; if it fails, all may receive the error. Proxies therefore apply a lock timeout, often a few seconds, after which waiting requests proceed independently.

The most serious risk involves uncacheable or personalized responses. If the node waits for a response that turns out to be private, queued requests cannot reuse it and must be sent to the origin one by one, a pattern known as request serialization. Varnish addresses this with a hit-for-miss or hit-for-pass marker that disables collapsing for that object for a defined period.

SymptomCauseRemedy
Long tail latency on missesSlow origin blocks all waitersSet a lock timeout and use stale content
Requests processed one at a timeUncacheable response serializes the queueMark the object as pass for a short period
User sees another user’s dataCache key omits a personalizing attributeExclude private content or fix the cache key
Origin overloaded after purgeCollapsing absent on some tierEnable it at the shield and the edge
Common problems and remedies

Never enable collapsing for responses that depend on cookies or authorization unless the cache key reflects those values, because sharing a response between users then becomes a data leak.

The idea in brief

Imagine a crowd at a library desk. Everyone asks for the same new book, and it is not on the shelf yet. The librarian does not send a separate person to the warehouse for each request. Instead, one runner goes, and everyone in line gets a copy when the book arrives.

Request collapsing does the same for websites. Many people may ask for the same file at the same moment. The delivery network then makes a single trip to the original server and shares the answer. This keeps that server from being overwhelmed.

A practical scenario

A news publisher posts a breaking story and sends a push notification to two million app users. Within ten seconds, roughly 40,000 requests for the same article page and its main image hit the CDN, while the objects are not cached yet. Without collapsing, each edge server would forward its own misses, and the content management system behind the origin can handle only a few hundred requests per second.

Because the CDN collapses requests at each edge node and again at an origin shield, the origin receives only a handful of fetches for each object. The article becomes cacheable after the first response, and later updates use stale-while-revalidate. The site stays responsive throughout the traffic spike, and the origin servers remain at moderate load.