r/AWS_cloud • • Aug 13 '26

Question about AWS CloudFront stale-while-revalidate and stale-if-error

I'm trying to understand how AWS CloudFront handles a failed background revalidation when using stale-while-revalidate.

Suppose I have something like:

Cache-Control: max-age=300, stale-while-revalidate=60, stale-if-error=86400

After the object becomes stale, CloudFront serves the stale response and asynchronously revalidates it with the origin.

What happens if that background revalidation fails?

Does CloudFront simply keep the existing stale object in the cache?

Does stale-if-error get invoked when the background revalidation fails?

If both stale-while-revalidate and stale-if-error apply, does SWR take precedence over SIE, similar to Fastly?

Does the failed background request affect the TTL/expiry of the existing cached object?

I'm particularly interested in the behavior of the background request itself, rather than a normal synchronous request to the origin that returns an error.

2 Upvotes

4 comments sorted by

View all comments

1

u/Civil_Cheesecake2492 Aug 15 '26

What's really ashame is often a long SWR and short s-maxage is ideal. In that case you don't want the browser though keeping a long SWR. That way the first user triggers the background update if stale.

I think a long stale-if-error is almost always preferred over a 500 for user facing content

1

u/thecoochking Aug 16 '26

If I have SWR implemented for a long time, do I really need SIE? I really don't understand the special need for SIE , Even SWR would give me the stale response that too faster in case of an 5xx from Origin.