0

I am wondering which is the best practice in Azure notification hub to send push notifications to a couple of certain users (e.g. about followed activities).

Imagine, users can follow other users and these followers should be notified about new activities (facebook, twitter principle).

How to send these notifications in detail, there are two options I am thinking about, but which one is the best?

1) looping through all desired users by code and calling SendTemplateNotificationAsync for each individual user?

foreach(user in allSubscribedUsers) {
    tags.Add("userid:" + userId);
    await hub.SendTemplateNotificationAsync(notification, tags);
}

2) Having special tags a user can register to

registration.Tags = new HashSet<string>(deviceUpdate.Tags);

// the current user follows other users with the ids 1,2 and 3
registration.Tags.Add("followerUserid:1");
registration.Tags.Add("followerUserid:2");
registration.Tags.Add("followerUserid:3");
...
// an acivity by user with id 2 is happen
// send a push notification to all users who follow the user with id 2
tags.Add("followerUserid:2");
await hub.SendTemplateNotificationAsync(notification, tags);

It's possible that a user follows up to 1.000 other users, so he needs to register 1.000 of the followerUserId-Tag.

Is the second approach a reliable solution?

Are there any tag limitations a user can register to?

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
Mica
  • 1,099
  • 9
  • 9

1 Answers1

0

This answer describes tag limits on NH. There is a limit of 60 tags per registration, so you won't be able to use your second approach if you want to allow 1k followers.

You can use the SendNotificationAsync(Notification, IEnumerable<String>) overload of the method to "batch" calls in your first scenario in groups of 20 max to save on the number of calls you make to the service.

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
  • Thanks for your answer! But the next following post in the linked thread, says, that MS had eliminate the tag limit? – Mica Jun 09 '17 at 09:23
  • 1
    This is a bit confusing, but there're many aspects to tag limits. The number of _tags per device_ is 60. But the number of _tags overall_ is capped at 3000. However, devices with <5 tags are excluded from the cap. So in your case, it would mean that if every user has 5 or fewer tags associated with them, you won't hit the 3k cap no matter how many users you have. – Nikita R. Jun 09 '17 at 16:56