During a user session requests are routed between scaled containers

We have a rails web app behind NGINX and Haproxy load balancer. Our web app has multiple containers, which we scale depending on traffic. We noticed that during a single user sessions, the requests often “jump” between different app containers. For us this is not a desired outcome (e.g. caching purpose) as we want to bind a single user session to a specific container.

How can we apply this in Rancher (e.g. Haproxy sticky session)? Is this at all an approach that makes sense? Thanks for any hints.

A photo says more than a thousand words… :slight_smile: Thanks for that.

Tested it in the past days and sticky cookies have no effect. Maybe Nginx is the reason for it, but in our case it is not working.

The UI/haproxy option will ensure that a request from a particular client goes to the same haproxy backend. If those backends are then nginx containers that send requests to multiple backends on their side, nginx also needs to do the same thing. Otherwise you’re just doing

client --> random haproxy --> sticky nginx --> random backend

which is no better than what you had before:

client --> random haproxy --> random nginx --> random backend

Got it. Thanks! Now it makes totally sense. I guess we have to re-evaluate our configuration then or find a way to keep the session persistent to the end.