I'm new on notifications with firebase and Cloud Functions and wondering if even using CF where servers are managed by Firebase's teams and has autoscale, is there a chance, if I was sending 100.000 notifications to my users, to crash my application?
I'm doing something like that:
- Someone on the app made a post;
- On my CF has a trigger to send notifications for the users;
- Then, all users (100.000) received the notifications.
Is Firebase infrastructure has queue or job manage to avoid this kind of situations or can I sleep well like a babe?
Here a snippet of my code:
exports.newPost = functions.database.ref("post/{postId}")
.onUpdate((change, context) => {
const before = change.before.val();
const after = change.after.val();
if (before.status === after.status) {
return null;
}
const ref = admin.database().ref(`tokens/`);
return ref.orderByKey().once("value", async snapshot => {
const fcmTokens = snapshotToArray(snapshot);
admin.messaging()
.sendMulticast({
data: {},
tokens: fcmTokens,
notification: {
title: 'Title',
body: 'Body',
},
android: {
notification: {
image: imageUrl,
},
},
apns: {
payload: {
aps: {
"mutable-content": 1,
},
},
fcm_options: {
image: imageUrl,
},
},
})
.then(resp => console.log(resp))
.catch(e => console.log(e))
})
})
My questions is: Is there a possible problem with my code?