06
Deep dive — sticky sessions vs true statelessness
Sticky sessions (session affinity) is the middle ground: the load balancer remembers "user Alice → server 3" via a cookie and routes her there for the session's duration. Server 3 keeps her session in memory. Fast, no Redis needed, but:
- Server 3 dies → Alice's session dies. She's logged out mid-session.
- Uneven load — long-session users pile onto one server.
- Scale down is dangerous — killing a healthy instance kills live sessions.
- Cross-service concerns — if Alice calls service B in the middle, does B also need to stick to her?
Sticky sessions are a pragmatic retrofit when moving to Redis is too expensive. But new systems should skip them. JWT-signed tokens + Redis session storage is the right default in 2025 — any server, any region, any replica can serve any request.
The exception: WebSockets. A WebSocket is inherently stateful — it's a persistent TCP connection to one server. For chat/real-time apps, you accept sticky connections + a pub/sub layer (Redis Streams, NATS, Kafka) to fan out messages across servers.