Thursday, 13 April 2017

Approach for building a realtime application [Node.js Socket.io Redis]

I'm building a realtime collaboration web app and the backend stack is Node.js, Socket.io, Redis, MongoDB and ElasticSearch.

(Approach #1) To create the real time updates, I compute, for each action, the users who are involved and then send the update event to them via socket.io. The mapping between the sockets and the users are on Redis, so after I know who are the users I want to update, I make some query in Redis to get their socket ids so I can emit the events.

At the moment I have only a few users using the app, but I'm worried that this approach won't be scalable, due to amount of calculations it requires for every action.

(Approach #2) Instead, I thought I could create a socket.io room for each "resource". This way I can send the updates on the room of each resource when needed (depending on the action) and the users that are in the room will receive the update. The last thing I need to do I to automatically join the users in the correct rooms, but this calculation is done only once per session.

With this approach I'm concerned about RAM consumption because the number of resources can be very high.

Is there another way to do this in a smarter and more efficient way? Any thoughts? What do you think about the approach #2 ?



via enrichz

No comments:

Post a Comment