title: Socket.io with PM2 Cluster in production - websocket vs sticky session
body: <p>I'm a bit confused. I'm using socket.io on my NodeJS Server using a simple:</p>
  
  <pre><code>const server = http.createServer(app);
  const io = socketIo();
  io.attach(server);
  io.adapter(redisAdapter(process.env.REDISCLOUD_URL));
  server.listen(3000)
  </code></pre>
  
  <p>Now I clustered my server process using PM2 Cluster option.</p>
  
  <p>My nginx configuration is straight forward as follows:</p>
  
  <pre><code>location / {
                  proxy_pass http://localhost:5030;
                  proxy_http_version 1.1;
                  proxy_set_header Upgrade $http_upgrade;
                  proxy_set_header Connection 'upgrade';
                  proxy_set_header Host $host;
                  proxy_cache_bypass $http_upgrade;
          }
  </code></pre>
  
  <p>Should I also add <code>websocket</code> transport instead of the normal http polling?</p>
  
  <pre><code>const server = http.createServer(app);
  const io = socketIo();
  io.attach(server, {
     transports: [ 'websocket' ]
  });
  io.adapter(redisAdapter(process.env.REDISCLOUD_URL));
  server.listen(3000)
  </code></pre>
  
  <p>In socket.io website they recommend <strong>against</strong> it and they suggest instead to balance load between nodes using <code>upstream</code> in the <code>nginx.conf</code> file with sticky session as follows:</p>
  
  <pre><code>upstream nodes {
      # enable sticky session based on IP
      ip_hash;
  
      server app01:3000;
      server app02:3000;
      server app03:3000;
    }
  </code></pre>
  
  <p>But my I don't have <code>app01</code>, <code>app02</code> and <code>app03</code>. I have my PM2 processes, but they all reside on the same <code>localhost:5030</code> address. So am I left only with the choice of enabling <code>websocket</code> transport and losing the fallback option for long-polling?</p>