Node.js › Clustering & Worker Threads
What is the difference between the 'sticky' and default load-balancing strategies when using Node's cluster module, and when does it matter?
IntermediateAnswer
By default the primary distributes connections across workers round-robin-like. 'Sticky' load balancing ensures requests from the same client always route to the same worker -- important for WebSocket connections or scenarios relying on in-memory, per-connection state on a specific worker.
const sticky = require('sticky-session');
if (!sticky.listen(server, 3000)) {
server.once('listening', () => console.log('Server started'));
}Real-world example A chat app clustering across four cores discovers WebSocket reconnections sometimes landed on a different worker than the one holding session state; sticky load balancing by IP resolved dropped connections.