What is request collapsing on a CDN?
Request collapsing merges concurrent misses for the same object into one origin request, so a cold cache does not send a crowd to your origin.
Request collapsing is when a cache merges concurrent requests for the same object into a single request to the origin, then uses that one response for all of them. Fastly defines it this way. Without it, a popular page that misses in cache sends every concurrent visitor to the origin at once, the thundering herd problem.
100 requests for /pricing, cache empty
without collapsing: up to 100 origin requests
with collapsing: 1 origin request, 99 wait for itCloudflare calls its version a cache lock: one request at a time goes to the origin for a given asset from a single location. RFC 9111 allows the practice, and `Cache-Status` has a collapsed parameter to report it.
- It protects the origin, not the visitor. The waiting requests are still slow, because they wait for the first one.
- It works per location. Each PoP, or each upper tier with tiered caching, sends its own request.
- Responses that cannot be cached, such as private pages, cannot be shared, so collapsing does not help them.
After a purge, cache warming avoids the herd by fetching each page before the crowd arrives.
Documented request collapsing is one of the criteria in the Top 10 CDNs comparison; the Fastly, KeyCDN and Bunny.net guides describe three implementations.
Related terms
References
- Fastly: Request collapsinghttps://www.fastly.com/documentation/guides/concepts/cache/request-collapsing/
- Cloudflare: Default cache behaviorhttps://developers.cloudflare.com/cache/concepts/default-cache-behavior/
- RFC 9211: The Cache-Status HTTP Response Header Fieldhttps://www.rfc-editor.org/rfc/rfc9211
Warm your cache after every deploy
sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.