Anonymous
8/3/2025, 5:44:59 PM No.106127445
So I have a server, to which users establish a persistent connection to using WebSocket. Occasionally, some user needs to be notified of an action taken by another user, so if the server sees that a user A sent some message on that WS connection that represents such action, it immediately checks for the users that need to be notified and sends the info to them on their WS connections, if they're connected at the time. So now I want to add the ability for the server to run in several instances. The problem is that, if a user A is connected to node A and the user B is connected to node B, the node A wouldn't know that user B is online at all because it can't see a WS connection from user B in its own memory. Clearly, some kind of coordination is necessary. The issue is this: I can't figure out how to do it. OK, say we have a centralized data store that stored user-to-node mappings. Now what? I could put an Apache Kafka and create a topic for each node, but what if some node X crashes and some other node Y checks the data store for the user-to-node mapping before the TTL for the mapping expires, then sends the activity notification into the topic for the already-dead node, and then the user that was on the crashed node reconnects to another node? At this point the notification is pretty much lost. How does one design this properly?
Replies: