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