Request collapsing
Request collapsing (also called request deduplication) turns identical requests that arrive at the same time into a single origin request. When a popular entry expires, your origin answers once, not once per waiting client.
How it works
Section titled “How it works”- Several clients send the same operation at the same time.
- They all resolve to the same cache key.
- One of them goes to your origin. The rest wait.
- The response is stored once and served to all of them.
Nothing is configured for this, and nothing can turn it off.
What it applies to
Section titled “What it applies to”Collapsing follows the cache, so it covers exactly what the cache covers:
| Collapsed | |
|---|---|
A MISS on a cacheable operation | Yes, this is the case it exists for. |
A PASS with a CACHE_PASS_* reason | No. The cache was never consulted, so there is nothing to wait for. |
A response that turns out not to be storable (a PASS with a CACHE_ reason) | No. No entry is written, so there is nothing to hand to the waiting requests. They are released and go to your origin themselves. |
| Requests with different variables | No. Different variables mean a different key. |
| Requests in different buckets | No. A private entry and a public one are different entries. |
The not-storable row is worth a second look. An operation whose responses are never stored
gains nothing from collapsing: every request reaches your origin. Under a burst, the waiting
requests may also reach it one after another rather than all at once, so an uncacheable hot
operation can take longer under load than the same operation with a freshness lifetime would.
If an operation should be cached, check its gp-cache-reason.
Why it matters
Section titled “Why it matters”- Thundering herd protection. When a popular entry expires, the next thousand requests for it do not all become origin requests.
- Cold start protection. A newly deployed service, or a location that has not cached an operation yet, takes one origin request per operation rather than one per client.
- It bounds the worst case. Origin load from cacheable traffic is bounded by the number of distinct operations in flight, not by request volume.
To keep even that one request from holding clients up at expiry, give the entry a stale window; see stale windows and request collapsing.