In my application users create “teams” (aka workspaces). I’d like to configure AWS ALB sticky sessions to route requests from the same team to the same EC2 instance so that in-memory team-level caches are more effective. It’s not a requirement that all requests go to the same EC2 instance but it would mean there are fewer cache misses.
The team ID is present in either the URL or an HTTP header depending on the request.
It’s unclear to me how to accomplish this from the AWS ALB sticky session documentation. In the section titled “Application-based stickiness” the documentation says:
Application-based stickiness gives you the flexibility to set your own criteria for client-target stickiness. When you enable application-based stickiness, the load balancer routes the first request to a target within the target group based on the chosen algorithm.
Which sounds like what I want? Though the docs don’t detail how to configure the “chosen algorithm” for that initial routing.
How would you accomplish routing multiple users of the same team to the same EC2 instance with AWS ALB? Is it possible?
2
Answers
Chosen algorithm
would be underTraffic configuration
in the AWS Console UI for the Target group. It can be one of:Now, for the primary part of your question:
If you want to route multiple people from the same team to the same target, you can use
application-based stickiness
as you mentioned. To use it, you need to generate a cookie in your application. When you are setting up the stickiness on the target group, set:Stickiness type
– Application-based cookieApp cookie name
– the name of the cookie that you will generate in your application (for exampleteam_session
)On the AWS ALB part, that’s it. In your application, you should now generate this cookie and make sure that the value of the cookie is the same for all members of the team, so incorporate that in the logic of generating this cookie for users.
You can:
But separate from your question, I have a concern:
Hope this helps!