Janosch Hübner
Janosch Hübner

Reputation: 1694

Firebase best practises with FCM topics or device groups

I want to use FCM and I'm not sure which option would apply best to my situation. Essentially I have artists in a database that users can follow, so for each artist I have a variable number of users that follow it.

Now if an artist releases something new, I want to send out a notification to all of the users that follow it. And here are my only options:

  1. For each user do: FCM send with users's token
  2. Subscribe a user to each "artist" topic (artist identifier) and send a notification to the topic of the artist identifier
  3. Create a device group with an identifier (artist identifier) and add user to the device groups for all the artists.

Issues I have with each of the options:

  1. Would create a large number of send promises (for each user)
  2. Would need to subscribe to all of the artists (there is no subscribeToTopics functionality, only for a single topic)
  3. Same as (2.) would need to create a device group for each artist and add the user to each of them.

I'd usually go with the 1. option and I was wondering if it can be done with let's say 1000 Users (so essentially a for loop 1000 times and each creates a send promise).

Is there anything I'm missing to send notifications to a large group of users which each could have a large amount of groups / topics?

Thank you

Upvotes: 1

Views: 1480

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

I'd definitely pick topics for your use-case, they're pretty much made for this. While option 1 would also be possible, it just feels senseless to manage the subscriptions yourself in this case.

If you want to allow someone to also subscribe to news about all artists, create a topic all and then send news about any artist to a condition: ('The Beatles' in topics || 'all' in topics).

Upvotes: 1

Related Questions