title: Loadbalancing web sockets
body: <p>I have a server which supports web sockets. Browsers connect to my site and each one opens a web socket to <code>www.mydomain.example</code>. That way, my social network app can push messages to the clients.</p>
  <p>Traditionally, using just HTTP requests, I would scale up by adding a second server and a load balancer in front of the two web servers.</p>
  <p>With web sockets, the connection has to be directly with the web server, not the load balancers, because if a machine has a physical limit of say 64k open ports, and the clients were connecting to the load balancer, then I couldn't support more than 64k concurrent users.</p>
  <p>So how do I:</p>
  <ol>
  <li><p>get the client to connect directly to the web server (rather than the load balancer) when the page loads? Do I simply load the JavaScript from a node, and the load balancers (or whatever) randomly modifies the URL for the script, every time the page is initially requested?</p>
  </li>
  <li><p>handle a ripple start? The browser will notice that the connection is closed as the web server shuts down. I can write JavaScript code to attempt to reopen the connection, but the node will be gone for a while. So I guess I would have to go back to the load balancer to query the address of the next node to use?</p>
  </li>
  <li><p>I did wonder about the load balancers sending a redirect on the initial request, so that the browser initially requests <code>www.mydomain.example</code> and gets redirected to <code>www34.mydomain.example</code>. That works quite well, until the node goes down - and sites like Facebook don't do that. How do they do it?</p>
  </li>
  </ol>