Iβm sorry, but I just couldnβt resist that clickbaity title. π Jokes aside, letβs say you have a monthly CRON job that empties out your usersβ trash and does some other Firestore related cleanup. This is a great use of Firebase Cloud Functions, but it comes at a cost: youβre creating/updating/deleting documents all in one go.
Remember, Firestore free quota resets daily. So if youβre too small to max out your free quota everyday, but too big to stay on the Spark plan, you should consider running daily jobs instead.
As long as your Cloud Functions only query the data theyβre going to process, then itβll be far cheaper to run a job every day and take full advantage of that free quota. As an added bonus, youβll be able to better predict your monthly bill because youβll be spreading out Firestore usage over each day.
Running daily jobs
Running a daily CRON job is ridiculously easy to do: simply create aCloud Scheduler job set to run at 3am each morning(0 3 * * *) that publishes an empty data payload ({}) to a topic of your choice (daily-tick). Itβll look something like this:
This tick is completely free!
In your functionsβ index file, subscribe to the daily-tick pubsub event and youβre good to go.
Hopefully this will help you save a few bucks. Happy coding!


Top comments (0)