Just like socket.io using redis adapter or something else for managing multiple connections
a
Andrew O'Hara
01/26/2024, 4:50 PM
Not sure if ktor websockets has anything to help with that, but here's some ideas:
• send the command to each server in your cluster over HTTP; servers not holding the target websocket will ignore it
• publish the active websockets to redis or any database, including the internal ip of the server holding it. Query for the internal ip and send the command to the server over HTTP
• write commands to a message broker; each server is subscribed and will process a duplicate of every command published; they will ignore the command if they aren't holding the target websocket
• If you're on AWS, replace your usage of ktor websocket with API Gateway websockets; it will handle the routing for you
👀 1
t
Todd
01/29/2024, 6:41 PM
So glad I happened upon this message! I never thought about the first three bullets you made. I really like those approaches. I was trying to solve this for a side project and was struggling to come up with a solution other than use a single server to handle websocket routing or something like the api gateway websockets.
Todd
01/29/2024, 6:41 PM
Thanks Andrew
🙂 1
m
Md Sadique Inam
02/01/2024, 4:12 PM
For the first point I think I have a better approach instead of sending requests to all servers it use better to use sticky sessions and keep the record of session
Md Sadique Inam
02/01/2024, 4:14 PM
But there is still an issue of how to manage multiple users in a group, if the users are scattered among multiple servers
A single source of truth will be needed