We’re trying to figure out a simple way to do dynamic sticky sessions <> docker replicas, but based on URL query params, not user IP
Imagine something like dynamic chatrooms, where there are more chatrooms than nodes, and they come & go: if a requested room isn’t being served, any node can pick it up, and while it is active, subsequent users of that room should go to the same node. We use websockets, so we’d like to persist those connections while live. It’s fine to retire/reassign a room as folks clear out.
Before addressing your actual question, I’ll say that this is a flawed approach. I would strongly recommend instead moving your chatrooms to using a centralized store so that it’s decoupled from your individual servers.
I recommend using Redis for pub/sub. All servers would subscribe to messages on behalf of each connected user, and each would publish messages to the appropriate channel (chatroom) which would fan-out to each server to send the message to the users in that channel.
Or if that sounds like too much effort, you could use an off-the-shelf solution like https://centrifugal.dev/ instead which does the heavy-lifting for you.
It doesn’t necessarily need to be “centralized”, Redis can be sharded. But either way, it’s just about moving the data pipeline to a service that is specifically designed to handle that kind of workload. It would allow you to scale your applications servers without worrying about specifics of load balancing.