0

I am adding a WebSocket handler to my Azure Webapp. Lets say that I am writing chat server (though I'm not), where the server will keep a list of all open connections in memory so that all connected clients can talk to each other.

Now, I have auto-scaling turned on so my server can some point in time scale out to 2 instances. Now clients connected to instance 1 cannot talk to clients who happen to be connected to instance 2.

To solve this I am trying to find out if it is possible to target a specific instance using Azures ARRAffinity cookie, but what I found so far, this is only possible:

  • For ordinary web requests (not "new WebSocket()")
  • From server to server using node.js

So my question, is it in fact possible in some way to this with websockets? Do you have some other suggestions?

EDIT 2017-11-02: This is still an interesting question, but I have solved it in a different (mostly positive) way: Since all messages going through the websocket is already serialized, it was easy to utilize my already present Redis cache publish/subscribe functionality.

So what I do now is:

  1. Message comes through websocket from client A - targeted at client B.
  2. Message arrives at webserver X (one of many possible webservers depending on scale out)
  3. Message is published to a Redis cache channel
  4. All webservers subscribes to Redis cache channel and receives the message
  5. The one webserver who happens to hold a websocket connection to the target client delivers the message, all other webservers ignore the message
  • If you are using node.js as your backend, check [this approach](https://stackoverflow.com/questions/18310635/scaling-socket-io-to-multiple-node-js-processes-using-cluster/18650183#18650183) see if it helps. – Aaron Chen Sep 26 '17 at 08:22
  • @AaronChen: nope, .NET backend. – Robert Kling Sep 27 '17 at 13:08

0 Answers0