🟢
Sticky Sessions (Session Affinity)
- Ensures the same client is always routed to the same backend instance
- Supported by CLB, ALB, and NLB
- For CLB and ALB: implemented with cookies (configurable expiration time)
- Use case: Maintain user session data without re-authentication or losing state
- Trade-off: May cause uneven traffic distribution between instances
Cookie Types
Application-based Cookies
- Custom Cookie
- Generated by target application
- Can include any required custom attributes
- Name must be set per target group
- Cannot use reserved names:
AWSALB
, AWSALBAPP
, AWSALBTG
- Application Cookie
- Generated by load balancer
Duration-based Cookies
- Generated by load balancer
Example Flow
- Client connects → Load balancer assigns target → Cookie is set
- On subsequent requests, LB routes the client to the same target until cookie expires