1
votes

I want to use socket.io, but I'll be running multiple instances of my app, so that's where things get interesting.

  • I need to run multiple instances on different ports. No problem here.

  • I decided not to use Node's own cluster, I'll use Nginx for load balancing (that's why I create multiple instances of the app). Nginx supports websockets, so this one is also sorted out.

  • Given that there'll be multiple instances, not all of them can't talk to each other directly (user A connects to instance X, if user B is connected to instance Y, they can't communicate since servers are independent from each other), so I need to use Redis' pub/sub mechanism as a wrapper in order to mimick socketio's emit & broadcast functionality. This way even if I have multiple instances of an app or run it on different servers, everybody will be able to talk to each other as long as they're connected to the same Redis server. To achieve this, I'll need to use socket.io-redis and socket.io-emitter modules.

Have I got that right, is there something wrong with this approach?

1

1 Answers

1
votes

Sounds about right probably except are you sure you need multiple instances of your Node app on different ports? Because you might be able to handle more load than you would assume with one server and there are ways to separate out different communications channels with socket.io.