Multi tenancy with Phoenix Channels

Before diving into the code to try to understand how the full system works, I want to know how hard it would be to make websockets & channels work with multiple pubsub servers.

Basically, the idea is to allow different clients to use their own channel names. Currently we have the client ID as a prefix to the channel name : "jwp:<client_id>:<name>" so we can direct connexions to our channel implementation (matching "jwp:*"). As the channel name is unique, it works well and different app do not have other apps messages. This is with the default Phoenix 1.5 setup.

Now, with multiple pubsub servers, it would be easyier to provide different channel implementations like "public:*", "private:*", "presence:*", "state:*".

I guess I can hack it some way, but is there a good way of doing it ? And how would it behave with distribution ?

Thank you.

Well, I am dump I didn’t even think about replacing the "jwp:*" prefix with those different prefixes.

My question still stands though: does multi-tenancy in theese terms can provide new functionality, and is it hard to do ?

Why do you need multiple pubsub servers vs 1 server that routes based on the topic (as Phoenix PubSub does)?

In this case, I might do something like <whatever_prefix>:<client_id> and then you can publish to them over the standard PubSub mechanism.

Yes, this is why I made my second post, there is a simple way to use different channel modules based on the prefix. But still we need to have the client_id in the channel name, which requires additional checks for authentication in the server and adds some indirection for the clients, as they can’t just call socket.channel('true_name').

Thank you :slight_smile:

The second post isn’t clicking for me. If the topic has the client_id in it, you can authorize that they are allowed to join/3 the channel, based on the socket state and the channel topic name. You authenticate in the socket connect function, and authorize in the channel join function based on the topic and assigns state.

1 Like

This is actually what we do.

What I want to know is if there is any benefit on using multiple pub sub instead of one per endpoint, and if yed, if it would not be to “hackish”

I can’t answer this because I haven’t tried or looked into the consequences. Curious if anyone else has done it.