We are developing a group chat app and we would like to know the recommended way to implement pubnub groups. We thought about 2 options: 1- Every user subscribes to only 1 private channel. A group would just be a list of private channels for the members, and every message would be sent to each user channel. For example: Group School: David, Alex, John. If John wants to send a message to school, he would just send a message to David's and Alex's private channels, tagging that this message belongs to the School group. This solution has the problem of requiring multiple publish actions, and an error could cause some desynchronisation with the users.
2- Every group would be a different channel, which the user would subscribe. We could also use channel group concept, where user only subscribe to the channel group, which has all private and public channels of that user. The problem with this solution is that if the user wants to retrieve the history of the messages of each group, then he would need a different API call to the server for each channel. For example. when launching the app we would want to get the messages received by the user since his last access. If the user subscribed only to one channel as in the previous alternative, it would require a single call to the API. If every chat were a different channel like in this case, it could get inefficient because of the multiple calls required.
Are there any better alternatives? What do you think about the above ideas?
Thanks, Daniel Ramos
Hi Daniel, you may be interested in the reviewing the following best practices guides published by PubNub Solution Architect Jasdeep Jaitla:
http://scalabl3.github.io/pubnub-design-patterns/2015/03/05/Inbound-Channel-Pattern.html (see "Group Chat" section at the bottom)
We're happy to discuss other design patterns that may be a better fit for your specific use case. Reach out to your Customer Success Manager or email@example.com to schedule an engineering best practices discussion.