Elixir/Phoenix approach for group chat application with large number of groups

I’m creating a mobile application with Elixir/Phoenix as backend. The purpose of this query is to clarify the approach I’ve taken for implementation as I’m primarily from a Java background and have chosen Elixir for my new product.

One of the core functionality of the app is a group chat feature wherein users can create groups and invite friends/family to collaborate. The approach i have taken is to have a private topic for each group and users “join” this channel/topic to get messages. In this approach if a user manages to make 50 groups, then he need to “join” to 50 topics when he opens the mobile application. In other words it be directly proportional to the number of groups he becomes part of.

While this is perfectly fine for me to implement, I request the expert opinion of this group to ensure my understanding/approach is correct.

Also is there any restriction on the number of users who can subscribe to a particular topic.

Thanks a lot in advance !!!

1 Like

In general I think the conceptual link between group -> topic/channel is correct. The phoenix client and server are smart enough to only open one websocket connection, and to handle the different rooms with namespaces.

In practice, however, with a large number of groups open and a high latency or low bandwidth connection, you likely want to have some mechanism of prioritizing messages for the group that is currently open.

One approach is to broadcast the text of the messages only to people with the group open, and just broadcast that a message has happened to everyone else, depending on your UX decisions.

You don’t have to worry about that for a while though :slight_smile:

Hello Ben, Good to know that the approach is correct. Appreciate and thank you for your quick feedback.

I’ve worked with a fairly similar setup at work. What we ended up with is that a user will only join the channel for a group when they are actively viewing the group but they are always connected to their own personal user channel. When a message comes in for the group it is always broadcast to that groups channel directly. And for any users that are not present at the time, if they are present on their user channel then they are notified there. Of they aren’t present on their user channel then we send a push notification (since the clients are mobile apps)

1 Like

Hello Axelson, agree with your approach and that would be the right track for a group intense mobile app. I’ll take the same route. Thank you.

1 Like