AWS › Elastic Load Balancing (ALB, NLB & CLB)
How can Application Load Balancer support sticky sessions, and when is this feature actually necessary for an application?
AdvancedAnswer
Sticky sessions, also called session affinity, let the load balancer consistently route requests from the same client to the same backend target for the duration of a session, using a cookie to track this assignment, which is necessary for applications that store session state locally in memory on a specific server rather than in a shared external session store, though it is generally considered a better long term practice to design applications to be stateless and store session data in a shared store like ElastiCache or DynamoDB instead of relying on sticky sessions.
aws elbv2 modify-target-group-attributes --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/abc --attributes Key=stickiness.enabled,Value=trueReal-world example A legacy application that stores user session data directly in each server's local memory temporarily enables sticky sessions on its load balancer while the development team works on a longer term migration to store session data in a shared ElastiCache cluster instead.