title: Scaling Socket.IO to multiple Node.js processes using cluster
body: <p>Tearing my hair out with this one... has anyone managed to scale <a href="http://socket.io/">Socket.IO</a> to multiple "worker" processes spawned by Node.js's <a href="http://nodejs.org/api/cluster.html">cluster</a> module?</p>
  
  <p>Lets say I have the following on <strong>four</strong> worker processes (pseudo):</p>
  
  <pre><code>// on the server
  var express = require('express');
  var server = express();
  var socket = require('socket.io');
  var io = socket.listen(server);
  
  // socket.io
  io.set('store', new socket.RedisStore);
  
  // set-up connections...
  io.sockets.on('connection', function(socket) {
  
    socket.on('join', function(rooms) {
      rooms.forEach(function(room) {
        socket.join(room);
      });
    });
  
    socket.on('leave', function(rooms) {
      rooms.forEach(function(room) {
        socket.leave(room);
      });
    });
  
  });
  
  // Emit a message every second
  function send() {
    io.sockets.in('room').emit('data', 'howdy');
  }
  
  setInterval(send, 1000);
  </code></pre>
  
  <p>And on the browser...</p>
  
  <pre><code>// on the client
  socket = io.connect();
  socket.emit('join', ['room']);
  
  socket.on('data', function(data){
    console.log(data);
  });
  </code></pre>
  
  <p><strong>The problem:</strong> Every second, I'm receiving <strong>four</strong> messages, due to four separate worker processes sending the messages.</p>
  
  <p>How do I ensure the message is only sent once?</p>