Reputation: 614
I am using two ec2 instances on a classic load balancer. My users were having 502 errors in the middle of their analysis, especially while having ajax calls. In other words, if a user is connected to a server instance, an ajax call in the middle of using the program is directed to the other server instance. And that causes that error. I need the user targeted to the same server instance during the his/her session.
After googling the issue mentioned above, I found this:
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
According to these documentations, I should apply sticky sessions to my load balancer. However, it requires clients to have their cookies enabled on their browsers. I really don't want that.
Is there any other solution for this issue? I really would appreciate any suggestion.
Upvotes: 1
Views: 1315
Reputation: 239000
The problem you are facing is because your application is statefull. In ideal load balanced and auto-scaled setup, all your instances should be stateless, which means there wouldn't be any issue with re-directing users to other instances.
For this to work, all state information related to your user's sessions should be stored and handled outside of the instances, e.g. in DynamoDB or ElasticCache. This will add more cost and requires changes to your application, but this is what you should aim at and it would allow you to pass stateid
in url, instead of cookies.
Sadly, I don't think you can achieve what you want without load balancer cookies or application level cookies.
Upvotes: 5