title: Load Balance: Node.js - Socket.io - Redis
body: <p>I have 3 Servers running NodeJs, and they are related each other with Redis (1 master, 2 slaves).</p>
  
  <p>The issue i'm having is that running the system on a single server works fine, but when I scale it to 3 NodeJS servers, it starts missing messages and the system gets unstable.</p>
  
  <p>My load balancer does not accept sticky sessions. So every time that the requests from the client arrives to it, they can go to a different server.</p>
  
  <p>I'm pointing all the NodeJS servers to the Redis Master.</p>
  
  <p>It looks like socket.io is storing information on each server and it is not being distributed with redis.</p>
  
  <p>I'm using socket.io V9, I'm suspecting that I don't have any handshake code, could this be the reason?</p>
  
  <p>My code to configure socket.io is:</p>
  
  <pre><code>var express = require('express');
  var io = require('socket.io');
  var redis = require('socket.io/node_modules/redis');
  var RedisStore = require('socket.io/lib/stores/redis');
  
  var pub = redis.createClient("a port", "an ip");
  var sub = redis.createClient("a port", "an ip");
  var client = redis.createClient("a port", "an ip");
  var events = require('./modules/eventHandler');
  
  exports.createServer = function createServer() {
      var app = express();
      var server = app.listen(80);
      var socketIO = io.listen(server);
  
      socketIO.configure(function () {
          socketIO.set('store', new RedisStore({
              redisPub: pub,
              redisSub: sub,
              redisClient: client
          }));
          socketIO.set('resource', '/chat/socket.io');
          socketIO.set('log level', 0);
          socketIO.set('transports', [, 'htmlfile', 'xhr-polling', 'jsonp-polling']);
      });
  
      // attach event handlers
      events.attachHandlers(socketIO);
  
      // return server instance
      return server;
  };
  </code></pre>