caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Load balancer sticky cookie should have a Max-Age configuration

Open JasonYuan869 opened this issue 1 year ago • 4 comments

I have a service routed with the following

reverse_proxy backend-blue:3000 backend-green:3000 {
    lb_policy cookie {
        fallback first
    }
}

This allows me to do zero-downtime upgrades on a stateful service by switching the order of the upstreams.

I think it would be useful to allow configuration of a Max-Age property for the cookie to ensure that eventually a client application will use the new backend when the cookie expires.

If this is a feature that seems appropriate for the project, I would love to help contribute!

JasonYuan869 avatar Jun 13 '24 04:06 JasonYuan869

Thanks for the issue. Do you have any suggestions as to what the config would look like for that?

mholt avatar Jun 13 '24 12:06 mholt

Perhaps something like this?

reverse_proxy backend-blue:3000 backend-green:3000 {
    lb_policy cookie {
        fallback first
        max_age 3600  # 1 hour
    }
}

It definitely makes more sense to use Max-Age over Expires since we're not trying to hardcode a specific expiration time but rather tell the cookie to refresh after X duration.

JasonYuan869 avatar Jun 13 '24 14:06 JasonYuan869

That LGTM. Want to submit a PR? :smiley:

mholt avatar Jun 13 '24 14:06 mholt

Consider using caddy.Duration

mohammed90 avatar Jun 13 '24 14:06 mohammed90