
Ask HN: Need help with websocket / redis  and system design? - techsin101
When user connects to server via websocket. Socket connections are stateful, the server it connected with, is the only server that would be able to communicate over that socket.<p>I&#x27;m designing a chat. There are n servers, each server containing n users&#x2F;sockets connected to it.<p>Chat has a feature, connect to random, that connects you to a random user chosen from across all servers.<p>Currently using PUB&#x2F;SUB via Redis to communicate among servers.<p>- Is Redis PUB&#x2F;SUB the best way to handle communication between servers when most of the communication can be between two servers not 1 to N.<p>user x is in Server A, user y is in Server B. All N servers are subscribed to &#x27;message&#x27; channel. x wants to send a message to y. Server A publishes on &#x27;message&#x27; channel. All N servers are lit, when only Server B needed it. Can I keep track which server the partner of x, the y, is connected to using Redis pub&#x2F;sub and only send to that server.. Broadcast vs Emit?<p>- How do I design protocol of partnering up users? First to describe the problem...<p>A -&gt; Req (need partner for user x)<p>B &lt;- Req<p>C &lt;- Req<p>B -&gt; Offer (user y available for user x)<p>C -X (no one available, doesn&#x27;t do anything)<p>A &lt;- Offer (process the offer)<p>C &lt;- Offer (doesn&#x27;t have user x, doesn&#x27;t do anything)<p>A -&gt; Accept (assigns user x&#x27;s partner to be user y and let other server know)<p>B (server crashed no longer exists, problem)<p>How would, Server A, know that, Server B, with y has crashed &#x2F; or y has left. And it should continue to search for online user. Right now it&#x27;s just sitting, thinking that it has paired its user x with another live user.
======
pictur
I suggest you develop with such a tool instead of using redis
[https://github.com/ClusterWS/ClusterWS/blob/next/.github/REA...](https://github.com/ClusterWS/ClusterWS/blob/next/.github/README.md).

~~~
techsin101
I checked it out, i think it's just a library for websocket. I find native
functionality to be good enough on browser side, and on server I'm just using
ws module.

