I have subscribed all the devices to a topic i.e around 1 million users. When notification is received in the device there is an action button which calls a REST api.
Now if I trigger a notification to all the devices subscribed to the particular topic, all the users receive the notification and tap on the action button, which calls the rest API to fetch data.
Too many rest API calls increase the CPU utilisation to 100% and my server stops responding.
Is there any way I can made FCM to send notification to all the devices subscribed to a topic in the batches so that my server can handle the load
Following solutions are workaround if there is no way to send the topic notification in the batch.
1. Delaying the time of display of the notification at the app side.
After the notification received on the app, You can decide when to show it to user. Write a logic in such way that, say some user will see the notification immediately as it received, some will see it after 2 minutes, some will see it after 4 minutes and so on.
You can use AlarmManager, Handler or something similar.
2. Create bucket of the topics
Suppose you have a topic as sport_news
. Divide the main topic sport_news
into sport_news_1
, sport_news_2
, sport_news_3
and so on. Implement your own logic to divide the users.
For example
users registered in day 1 will fall into sport_news_1
users registered in day 2 will fall into sport_news_2
and so on.
So whenever you have to send notification to topic sport_news
then you will send the notification to all the topics belong to it, in our case it will be sport_news_1
, sport_news_2
and so on. You can send it on certain interval to handle the batches since you have the server side control to send it in the batches.
3. Scale the server for certain interval to handle the large traffic.
After sending the notification to some million users and knowing you will get the high traffic then scale your server for certain time to handle the large traffic(say 1-2 hours).
4. Improve the latency of your fetch data api
Knowing that you will get too many request for the particular fetch data api, You can implement caching, database indexing, in memory data store or any other way to speed up the fetch operation. You just have to find a way to reduce the response time for the fetch api in some way and your server will serve much traffic this way and cpu utilisation might reduced.