Firebase FCM short lived subscriptions to topics - firebase

I am hoping to use Firebase FCM for the following scenario but do not know if it is feasible:
A reasonably large number of users (100000+) subscribe to one of a fixed number of topics (around 10000) for a very short duration (1-5 minutes) before unsubscribing and subscribing to another topic. Each user only subscribes to a single topic at any one time and for the short period that they are subscribed to each topic, I can send messages to all subscribers almost immediately after they subscribe.
Is this practical?
Are subscriptions / unsubscriptions handled in near real-time?
Is this better handled another way such as sending by registration id and handling the 'topic' myself?

First question - why do you have 10000 topics?? Even with a single device having that it wouldn't be manageable.
Is this practical? No.
Are subscriptions/unsubscriptions handled in near real time? No, that is not how subscriptions work.
Last q's ans => https://stackoverflow.com/a/44934299/8525451 [doing it via registration_ids]

Related

Firebase & One Signal Push Notifications Guidance

I have been playing around with One Signal & Firebase Push Notification.
I am almost sure One Signal cannot help me and am starting to feel Firebase might also not be able to help me.
We have a web app that allows regular authors to post articles. It also allows users to comment on the article using Firebase synced realtime database.
I want to create functionality where users can get a push notification for article-specific comment treads. The room ID will be the article ID. If both allow push notification generally from our app and has commented on an article, they subscribe to this article comment tread solely. They can also click a button at this specific article comment thread and unsubscribe to this article comment thread if they want.
So we may have thousands of articles and hundreds of comments in each article, to put it lightly.
I quickly moved away from One Signal when I didn't feel like I could have a separate "Segment" for each article, I wasn't certain this is allowed? Thoughts there?
Throughout my exploration of Firebase I just came across this comment in their documentation in relation to groups (Which I was hoping could be my article room).
"The maximum number of members allowed for a notification key is 20" found here. A key is a group key from my understanding. This won't work because what if there are more than 20 users in a comment thread. I looked up the most popular commented threads ever to find numbers like 500. This means my system would have to be able to support large numbers of users per article tread.
Additionally One Signal Tags and Social activities look like could be investigated, but my general question is not specific, its more a wider general question. I am hoping someone with experience can give some guidance and good tips on best way to approach this problem. Are Push notification even allowed on such a scale I am wondering?
A scaling examples
1000 Articles with 100s of different users commenting on each article. A user may only receive a push notification on articles which he has commented in only.
(Assuming he has allowed push notification site-wide first and not blocked us or unsubscribed from the site entirely. Subscribing to the site doesn't automatically subscribe you to anything specific, just means you willing to be subscribed to something and have control which things easily)
Ok thanks for reading and looking forward to hearing from someone with this experience and share their experience.
Daniel Gadd # GaddBox
Maybe it's a bit late.
You have to use topics.
FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices.
In your case, every Article is a topic.

FCM topic limits and expiration/invalidation of old unused topics?

I have been using FCM topics for a while now, but the documentation is very limited and most searches leads to the same pages, so I am asking here, in hope someone has enough experience on the subject to answer my questions.
I am wondering if there is a limit to how many topics are allowed and what happens to topics that are no longer in use? I mean, when will a topic be invalid?
I have had issues where unsubscribing from a topic didn't seem to work, even if I get a positive response back or other times the notifications have been sent twice.
To get around this, I am currently making a new command, but unlike before, every time the command is run, I will subscribe tokens to a unique topic, send the notification, unsubscribe token and then that topic will never be used again. This is a way for me to have better control over which users gets subscribed to certain topics, as FCM offers no help with this, that I am aware of.
So here my question is, should I unsubscribe all the tokens again afterwards, letting FCM know that it is no longer in use, or would that be pointless to do? (In case they have some sort of clean up in place)
Hope someone can guide me in the right direction.
I am wondering if there is a limit to how many topics are allowed...
No limit.
...what happens to topics that are no longer in use? I mean, when will a topic be invalid?
A topic is created when there is at least 1 subscriber and it also gets automatically deleted when there are no more subscribers.
To get around this, I am currently making a new command, but unlike before, every time the command is run, I will subscribe tokens to a unique topic, send the notification, unsubscribe token and then that topic will never be used again. This is a way for me to have better control over which users gets subscribed to certain topics, as FCM offers no help with this, that I am aware of.
This use case doesn't seem to be wrong per se. It's just a bit unconventional (although I'm pretty sure I suggested something like this before).
Currently, with FCM v1, the registration_ids parameter (used to send to multiple token -- 1000 each request) is no longer advised. FCM team seems to be moving towards using topics for sending to multiple tokens. With that said, IMHO, I think the use case is valid.

Android notification channel maximum count

I am new to implement Android notification channel in Oreo. What is the maximum number of notification channels for a single application. Can we create unlimited channels or it has some count?
As far as I know there is no limit on the number of channels an app can create. The only purpose of NotificationChannel is to give more control of notification behavior to the user. It is no way to reduce the number of notification per app.
You can read about Notification Channel in detail at Create and Display Notification on Android Oreo | With Example
There is a limit that is not documented on the number of channels you can have at the same time, but no limit on how many times you can create a channel, as long as you have deleted other channels.
The file PreferencesHelper.java contains a limit that is currently set to 50.000
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/services/core/java/com/android/server/notification/PreferencesHelper.java
And this is being used to restrict the creation of more channels when it goes over that limit, throwing the exception "Limit exceed; cannot create more channels"
Unfortunately that value is not publicly accessible, so any limit check you might want to implement will have to be hardcoded by yourself. My suggestion is to set your own limit to a number that you think starts being unreasonable, and when that is reached you run a check on your notification channels to figure out what is going on, and fix it. For example, if your app will never need more than 5 channels to be created, then setting the limit to 6 would be a good way to start.
The commit https://github.com/aosp-mirror/platform_frameworks_base/commit/f528b337dd48b7e8071269e07e610bd4a3668c75 update the max notification channel to 5.000
Coming with Android Oreo, Notification Channels are something a developer uses to break down the notifications his or her app can give to us by type. The channels are decided by the people doing the developing, and the idea is to give us a way to separate out the notifications that are important to us from the ones that aren't, then decide how they will be shown. Some apps will have a lot of different channels. Some will have just a few and some will have only one.
In versions of Android before O, a developer used what was called a priority level to decide how to show you a notification. If they felt the notification was important, they could set it to peek (show a visual indication on your screen) or make a sound, or both. If they felt it wasn't it would just be placed in the tray for you to see the next time you went through them.
Now they break things out into channels and we get to decide how each type of notification is displayed. All notifications of the same type (for example, a reply on your Twitter feed) are placed into the same channel without any other types of notification grouped with them.
As a bonus, apps that allow us to use more than one account can have channels for each combined — your personal email and work email can follow the same rules and show you things the same way no matter which accounts received the notification.
You should read this:
https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels
Example:

Firebase rate limiting reads in secuirty rules

I have authenticated users and would like to be able to protect myself from users spamming reads on a particular ref (thus driving up costs), how do you do this? I see the question here:
Firebase rate limiting in security rules?
That involves rate limiting writes by:
"The trick is to keep an audit of the last time a user posted a
message" - Kato
Is there a way to determine the last time a user read, and then limit their next read to some time interval from their last read? Probably better is limiting the amount of reads in a certain timeframe (say n reads per hour)?
Thanks
I just read that firebase uses a burstable billing plan, as seen here:
https://en.wikipedia.org/wiki/Burstable_billing
Such that you are not charged for spikes from a malicious user doing what I describe here or from a DDOS.
How about this:
A structure:
posts
post_id_0
msg: "a post about posting"
post_id_1
msg: "a post about pizza"
and a users node
users
uid_0
name: "biff"
post_activity
post_id_0
last_activity: "20170128100200"
pseudo-code since we don't know the platform
display a lists of posts in a table
a post about posting
a post about pizza
user taps or clicks 'a post about posting'
in code, get the last activity, which was today at 10:02 am
lastActivity = uid_0/post_activity/post_id_0/last_activity
and then compare the last activity to the current time, and if it's been accessed less then a minute ago, don't allow them to read it again
let currentTimestamp = current time (say it's 10:04 am)
if currentTimestamp - lastActivity > 1 minute then
show post details
update the lastActivity node to current timestamp
else
print("Posts can only be reviewed every minute")
In this case the last time the post was read 2 minutes ago, so allow it to be read again. If it was less than a minute it would be denied.
Also, if the user would tap/click post_id_1 the post activity would not be found which means the user has never viewed it before; in that case add it to the uid_0/post_activity node.
The same technique could be used with a counter instead of a time to limit the number of times the user reads a post.

Drupal Notifications - Users receiving duplicate emails

We are using Drupal (5.x) Notifications module.
Our users are receiving duplicate emails (related to forum posts)
First email has this subject line: "Your Daily xyz Discussion Digest"
Second email has this subject line: "xyz subscription update for UserABC"
Content is somewhat similar. (formatting is different).
Tried to google for solution. No luck yet.
Any one seen this issue before?
Any suggestions?
sounds like message duping:
Deduping
There may be also more than one
subscription producing multiple
notifications for the same event. I.e.
if you are subscribed to 'story
updates' and subscribed to the
specific thready 'my story 1', then
updating 'my story 1' will actually
produce two notifications, one for
each subscription. These go through
some deduping process before being
sent out, merging notifications for
the same event into one notification.
However, this can be done if (and only
if) both subscriptions are using the
same sending method and the same
sending interval. Otherwise you'll be
getting two or more different
notifications for the same event.
see http://drupal.org/node/318577

Resources