Q34: How do Sticky Sessions work when load balancing WebSocket connections across Node.js cluster workers?

WebSockets require initial HTTP upgrades that transition into persistent TCP sockets. In a clustered Node.js environment, if handshake requests land on worker A but subsequent frames land on worker B, connection state breaks. Sticky sessions ensure that all requests from a single client IP or session cookie are routed consistently to the exact same worker process.

Key Takeaways
  • Stateful protocols like WebSockets require persistent routing to the same worker instance.
  • Sticky sessions route requests consistently using IP hashing or session cookies.
Knowledge Check

Why are sticky sessions required when load balancing WebSocket handshakes across multiple cluster workers?