When to use socket io adapters like Redis?

Viewed 31

The Socket.IO documentation says:

When scaling to multiple Socket.IO servers, you will need to replace the default in-memory adapter by another implementation, so the events are properly routed to all clients.

Does it mean that we need to use adapters like Redis only when scaling to multipe servers?

I am planning to implement a chat application with 2 thousand online users. If I only have one server, is it ok to use javascript array to hold online users?

1 Answers

Does it mean that we need to use adapters like Redis only when scaling to multiple servers?

Redis adapter is useful when you want to route socket messages between users connected to different workers of the same server or send messages to a bunch of users with .broadcast(). I dont think that it's a good idea to use it to route messages between servers. Indeed, redis adapter is based on pub/sub mecanism and should no be scaled using redis cluster and is (as such) useless as soon as message rate exceed ~100k/s.

I am planning to implement a chat application with 2 thousand online users. If I only have one server, is it ok to use javascript array to hold online users?

Using a javascript global variable is never recommended. Moreover, i don't know if a single worker can sustain 2k users, anyway you should have a nodejs cluster with sticky sessions enabled, so, you should have an adapter (that you can create yourself if most of messages are 1-1 and not 1-n, by creating a pub/sub channel named for example channel:userId and listening to it)

Related