AWS Sticky Sessions (Session Affinity) in Load Balancers
Sticky Sessions, also known as Session Affinity, allow an Elastic Load Balancer (ELB) to consistently route a client’s requests to the same backend instance. This ensures session continuity, preventing users from losing session data when making multiple requests.
How Sticky Sessions Work
- Normally, an Application Load Balancer (ALB) distributes traffic evenly across multiple backend instances.
- With sticky sessions enabled, a cookie is used to associate a client with a specific instance.
- Future requests from the same client will always be routed to the same backend instance until the cookie expires.
Use Case for Sticky Sessions
✅ Maintaining session data (e.g., user logins, shopping carts).
✅ Ensuring stateful applications function correctly without relying on external session storage.
⚠️ Potential downside: Can lead to uneven load distribution if some users generate significantly more traffic than others.
Supported Load Balancers
- Application Load Balancer (ALB)
- Network Load Balancer (NLB)
- Classic Load Balancer (CLB)
Types of Cookies in Sticky Sessions
1️⃣ Application-Based Cookie
- Generated by the application itself (not by the load balancer).