3

I am writing some NodeJS an application for some clients (mobile, single page app...). The application is game and quite social - users can have friends and game needs to sharing events between them in realtime. So I decided to use Socket.io.

How to effectively share events between connected sockets of user's friends? One user can be connected with more then one client (so he has more connected sockets). Is it good idea to use socket.io "rooms" where each user has one room and when some event occurs, it is emited to each room of my friends? How to effectively handle this?

For better notion you can imagine it the same way as facebook wall (or right panel of friends activity).

How would you handle it?

vaclav_o
  • 1,705
  • 3
  • 15
  • 24

1 Answers1

3

You could try solving this task with socket.io rooms but i think that would kill your application because of the overhead, for example

1000 users => equals => 1000 rooms ( 1 room for each user )

thats 1000 connection without anyone particularly listening to friend activity. So the approach above already seems like not scalable.

I would try publish/subscribe pattern which is not very difficult to implement, you can use a micro library or Backbone with .listenTo or even socket.io with Redis pub/sub.

  • A user would have the option to listen or stop listening to a friend events.
  • One user would not get a ton of notification for simple friend event.

and the list goes on depending on your application behavior. Some questions that have interesting information.

What should I be using? Socket.io rooms or Redis pub-sub?

Node.js, Socket.io, Redis pub/sub high volume, low latency difficulties

Community
  • 1
  • 1
Gntem
  • 6,949
  • 2
  • 35
  • 48