Josh
Josh

Reputation: 123

FCM for group messaging notifications - send to topics vs send to multiple tokens?

I'm trying to send notifications for a messaging system between users. I'm still quite new to this so I'm not sure which method I should be using to send notifications for replies to chat groups. Currently I'm thinking of either:

  1. Subscribe each chat participant to the chat id as a topic then push all new messages to the topic. This seems to be more efficient in resources by offloading the one-to-many nature to Google's servers. However, it seems like topic notifications don't have the ability to set the title and I'm not too sure about the security point of it.

  2. Send the notifications to the token ids of all chat participants each chat. This seems to be very resource heavy as my app server would have to send the entire list of participants for each message.

Appreciate any advice.

Thank you.

Upvotes: 3

Views: 1567

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

If a user knows a topic, they can subscribe to it. So you'll typically only want to use topics for information that anyone is allowed to subscribe to. So if your chat rooms are by their nature public, topics are probably a great fit. If your chat rooms may also be private, you'll probably want to not use topics for sending notifications about them.

Sending notifications to a load of tokens may require more server resources, but it not a problem for FCM. It sends many billions of messages to specific tokens per day, so should handle your scale without problems.

One optimization (mostly for your own code) is to send a single message to multiple tokens as a batch. You can send up to 500 tokens at once this way, so reduce the number of calls a lot, but making each call more complex (although probably not 500x more complex 😊).

Upvotes: 2

Related Questions