1

I'm building a web application that will allow team collaboration. That is, a user within a team will be able to edit shared data, and their edits should be pushed to other connected team members.

Are Socket.io rooms a reasonable way of achieving this?

i.e. (roughly speaking):

  • All connected team members will join the same room (dynamically created upon first team member connecting).
  • Any edits received by the server will be broadcast to the room (in addition to being persisted, etc).
  • On the client-side, any edits received will be used to update the shared data displayed in the browser accordingly.

Obviously it will need to somehow handle simultaneous updates to the same data.

Does this seem like a reasonable approach?

Might I need to consider something more robust, such as having a Redis database to hold the shared data during an editing session (with it being 'flushed' to the persistant DB at regular intervals)?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
William
  • 13,332
  • 13
  • 60
  • 73

1 Answers1

2

All you need is Socket.IO (with RedisStore) and Express.js. With Socket.IO you can setup rooms and also limit the access per room to only users who are auth. Using Redis you can make your app scale outside a process.

Useful links for you to read:

Handling Socket.IO, Express and sessions
Scaling Socket.IO
How to reuse redis connection in socket.io?
socket.io chat with private rooms
How to handle user and socket pairs with node.js + redis
Node.js, multi-threading and Socket.io

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • Thanks for that. So, am I right in saying that the use of Redis in this case (and perhaps in an app like Trello), isn't to store the actual data that the users are working with. Instead, it is simply to store the actual session data (i.e. current socket.io rooms, etc). The reason being that at scale you will have more than one Node.js process, and they will all need to share the same session data? – William Dec 21 '11 at 17:05
  • That one of the reasons, the most important. The other one is that Redis can do pub-sub. – alessioalex Dec 21 '11 at 17:38
  • The pub/sub is used by RedisStore to handle synchronisation of the session data between multiple nodes, right? i.e. it is still my custom Socket.io code that is responsible for broadcasting edits to team members in the example above? – William Dec 21 '11 at 17:48
  • Yes your custom code is delivering the messages to the browser, but when you app is big and you use multiple processes, not all clients are connected to the same 'node' (processes). So Redis is used to communicate between the Socket.io processes and also to share the session data globally between processes. – alessioalex Dec 21 '11 at 18:12
  • But can redis&socket.io scale well in multi-servers? I have figured out to use redis&socket.io in a single server with multiple nodes. But I am having a big trouble using socket.io in multiple servers with redis. – user482594 Dec 21 '11 at 19:57