7

I am looking into incorporating Google Cloud Messaging into my app. I would like to send messages to all devices associated with a user. At first, it looked like GCM's device group messaging would be the way to go. But that requires managing registration IDs and notification keys on my server. It seems like it'd be easier to use GCM's topic messaging where the topic is keyed on some shared user information like a user ID.

I intend to use GCM to send data to both Android and iOS apps. I will be sending both background "content available" (to use the Apple Push Notification terminology) messages and user-visible notifications.

What advantages are there, if any, of device group messaging over topic messaging?

Joe Shaw
  • 22,066
  • 16
  • 70
  • 92
  • 1
    Device group is for smaller scale, it can have 20 devices in a single device group, a use case will be sending a message to a specific circle of friends. But every topic can have 1M subscribers, a use case will be sports fans receive notification from a game. – ztan Dec 01 '15 at 21:41
  • 3
    In my case that doesn't matter much, because I don't anticipate having users with more than 20 devices. In reality I'm likely to be publishing to 1-5 devices, so either device groups or topics would suffice. Is there anything I am leaving on the table by choosing topics over device groups? They're substantially easier due to the lack of additional state. – Joe Shaw Dec 01 '15 at 22:17
  • 2
    For device group, you can easily add or remove devices using HTTP requests in your server. But for topic message, subscribe and unsubscribe methods are implemented in client side, so your users have to do things in client side to subscribe/unsubscribe. – ztan Dec 01 '15 at 22:31
  • 2
    I would recommend using topics over device group since you don't have to manage the list of members on the server side, no need to worry if a devcie token is valid or not. Note that the topic limit is currently 1M subscribers per APP not per topic, but it seems that this limit will not affect you. – Arthur Thompson Dec 02 '15 at 19:33
  • @zten Instance-Id API allows adding and removing devices from the server side if you have registration tokens. – kirtan403 Nov 14 '16 at 14:18

2 Answers2

2

I think the first point below is the only thing that makes any difference

https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

  • Topic messages are optimized for throughput rather than latency. For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens, not topics.
  • If you need to send messages to multiple devices per user, consider device group messaging for those use cases.
Sreekanth
  • 2,887
  • 2
  • 16
  • 30
1

GCM (Google Cloud Messaging) is now known as FCM (Firebase Cloud Messaging).

  • For device groups the maximum number of devices allowed for a notification is 20. It is good for a Whatsapp notification to an iPhone and two iPads that belong to the same person. It also maybe a family subscription to an application.
  • A topic may have, in theory, unlimited subscribed devices. The main limitation is that one app on a user's device can be subscribed to no more than 2000 topics. Good example is (https://firebase.blog/posts/2023/05/cloud-messaging-world-cup-scale) FIFA World Cup 2022 and a topic per play. There is no limit in topic numbers, so it can be weather forecast with a topic per city.

Update to the @ztan's valued points: it is possible to subscribe and unsubscribe devices for the both types of messaging, device groups and topics. The main difference is that topic messages are public, anyone can subscribe to a topic and view it. With a group it is possible to send messages privately to specific devices.

If there is a need to send message directly to a single device or a bunch of devices, it can be done with direct private messaging or private multicast messaging, the limit is higher than in groups, 500 messages per request, and it is possible to send multiple batches one by one.

enter image description here

Artur A
  • 7,115
  • 57
  • 60