Serve stale content if backend is healthy but "not too healthy"

Dridi Boukelmoune dridi at
Tue Sep 21 14:36:53 UTC 2021

On Tue, Sep 21, 2021 at 1:33 PM Luca Gervasi <luca.gervasi at> wrote:
> Hello everyone,
> We have a backend that actually proxies different services (mangling
> the original response). Sometimes one of those backends are not
> available and the general response goes from 200 to a 50x.
> Is there a way to serve a stale (valid) content (if present) for a
> request that comes from a backend in a healthy state?
> I was thinking about something like this:
> sub backend_fetch {
>   if (beresp.status >= 500) {
>     return_a_stale;
>   }
> }
> From the state machine
> ( it seems
> that I'm not allowed to return(hash) nor switch to an unhealthy
> backend (that i keep configured) to reach what I want.
> Please forgive me if do exists a facility to reach my goal and feel
> free to direct me to the right document.
> Ah. Varnish 6.x.

Hi Luca,

Varnish Cache does not have this feature, you should be able to do
that with Varnish Enterprise instead. What you are looking for is
stale-if-error and you may find some implementations using VCL but I
can't vouch for any, not having experience with them.


More information about the varnish-misc mailing list