Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP: Best approach for sending scheduled notification

I'm working on a reminder-like app that will need notifications to be sent at a specific time. Basically, users will create some sort of reminders and I will need to send the notifications at the specified time. I'm using Firebase Cloud Messaging for sending notifications.

What I have in mind right now is to store all the requests in my database and have "crawler" services that will be triggered every day to check all the requests and send the notification if needed.

This works fine with a small number of users, but if I get lucky and my app attracts tons of users, these services will have to handle millions of requests each day, and I prefer not to do that expensive operation.

I'm open to all solutions but prefer something from Google Cloud.

like image 967
Son Nguyen Avatar asked Nov 15 '25 17:11

Son Nguyen


1 Answers

You can use a Firebase Function with a Cloud Scheduler as its trigger.

Let's say you configure that scheduler to run every minute. That's still 1 * 60 * 24 * 30 = 43200 function runs for every 30 days. That's still very low compared to the pricing of Firebase/G Cloud Functions.

I'm doing something similar.

I use Firebase Firestore (same as Cloud Firestore).

For every user, I have a " time_to_send " field. When the function runs, it queries the users who have a " time_to_send " value that is smaller (in the past) or equal to << Now >>.

For those users (usually a small number because it runs every minute), the function sends the notification and updates the " time_to_send " to a value in the future (the next time they should be notified).

So that means, in terms of costs, you have to calculate:

  • 43.2k scheduled function runs per month
  • (Number of users) X (average # of notifications per user per month) X (1 database read + 1 database write)

You'll have to calculate if this approach is affordable to you or not.

like image 81
MarketerInCoderClothes Avatar answered Nov 18 '25 10:11

MarketerInCoderClothes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!