Ask HN: Need help with websocket / redis and system design?
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.