0

I'm designing a Java Spring based real-time notifications system & chat system using Redis & WebSockets(with sockJS and STOMP). Requirement is for each user to subscribe to a unique channel (channel name will be user id). This is because notifications can be targeted to a single user and chat conversation can be 1-on-1. The very reason im using redis is to get an event triggered in the corresponding application server(there are many) where the user is connected via WebSocket. As I understand, when a publish happens to say "user1" - and if I want to get the "onMessage handler" fired for just that target user:

  1. Do I need to maintain 1 redis connection per user ?
  2. is it okay to open 15k connections at a time with 15k unique subscriptions for those many users connected to the system at once?
user1102532
  • 495
  • 6
  • 16
  • How does the system know which application server the user is connected know that there is a new message for the user or is that what you are asking? – goblinjuice Aug 06 '17 at 16:28
  • The system knows because Redis will fire an event handler in the respective app server where the user is connected to. Say user-a connected to appserver-a, user-b connected to appserver-b. When I publish a message to a channel that both users have subscribed to, redis will trigger an event in both app servers, and in the event handler I have code to send the message to the user via websocket the user is connected with. – user1220169 Aug 08 '17 at 17:36
  • My problem is this. In the scenario where user-a is subscribed to channel-a and user-b to channel-b and both of them connected to the same appserver - I need to have 2 separate connections to redis for each user. So that when I publish a message to user-a, the event is triggered only on connection-a where user-a's eventHanler is listening to and user-b does not get this message since he/she is connected via an entirely separate connection. I need to know if this is a good approach. – user1220169 Aug 08 '17 at 17:39
  • Another approach is to just have 1 connection per app server, keep adding the eventHandlers to the same redis connection and subscribe to all the channels. In my eventhandler I need to check if the message is intended for the current user and send only if true - ignore the message for the other users. Problem is all eventhandlers will be fired. But is that better than having 1 connection per user? is what Im trying to figure out – user1220169 Aug 08 '17 at 17:43

1 Answers1

0

Since you have tagged the question with Redisson, I presume you are using it already. If your choice of WebSocket framework is flexible, i.e. not limited to be SockJS with STOMP, you could consider the netty-socketio project. It is written by the author of Redisson and the integration between the two can't be any more natural.

Netty-socketio is fully compatible wit the popular SocketIO client side JS library and it is used by plenty companies commercially.

It doesn't require one redis connection per user and there are people whose usage are known to have already exceeded your requirement.

This is mentioned in the project's README file.

Customer feedback in 2014:

"To stress test the solution we run 30 000 simultaneous websocket clients and managed to peak at total of about 140 000 messages per second with less than 1 second average delay." (c) Viktor Endersz - Kambi Sports Solutions

Community
  • 1
  • 1
Redisson_RuiGu
  • 1,012
  • 10
  • 13