Sticky sessions ensure that requests from the same client always reach the same worker. This is achieved using Nginx ip_hash directive, the socket.io-sticky package, or Redis adapters for WebSocket applications, ensuring session continuity across requests.
By default, the cluster module distributes connections using round-robin, so the same client's requests can land on different workers each time. This breaks features that rely on in-memory state per worker, like WebSocket connections or server-side sessions stored in memory. Sticky sessions route each client consistently to the same worker based on IP or session cookie.
Nginx ip_hash — routes same client IP to same upstream server (most common)
HAProxy source balance — similar to ip_hash but with more configuration flexibility
socket.io-sticky npm package — lightweight sticky session support for cluster module
Cookie-based routing — load balancer reads a session cookie to determine the target worker
Redis adapter for Socket.IO — allows events to broadcast across all workers, reducing need for strict stickiness