Managing Firebase Costs
Firebase provides us 3 plans for their pricing: the free Spark plan which gives generous allocations to most of their products for many hobbyists and indie developers; the fixed Flame plan which costs $25/month to give a project bigger allocations to Firebase product usage; and the wild Blaze plan whose cost scales with your usage of it.
Blaze is the most expensive choice
At first glance, you probably have this in your head. It doesn’t take a lot of thinking to realize this isn’t always the case. It’s pay as you go. It can cost you barely $5/month if you’re using it way below Flame plan’s regular limits. There is one truth to Blaze, however…
Blaze Plan is Risky
Several developers and startups have fallen into the trap that what they think is going to be a sane $10 bill actually turns out to be $4976. Ain’t that just a fun time?
Now now, several of these cases are attributed to bugs and mishaps on the Firebase Team’s part, and they do get solved thanks to their amazing support team, but in less extreme cases, seeing your plan higher than it should be can be quite infuriating.
This is why I’m going to list a few things you may or may not know about Firebase which could be affecting your monthly quota and what you can do to optimize it fully.
Let me first get some obvious things out of the way. Things I hope you know already:
Blaze Plan includes free usage from Spark Plan
This is displayed quite clearly on the Blaze Plan header. This means if your project is subscribed to the Blaze Plan but your usage is well under Spark Plan’s usage, you might as well not be paying a cent.
Before Starting: Use the Blaze Plan Calculator
The Firebase guys are nice. They give you a handy calculator on their pricing page to help you estimate your monthly billing costs. Try tweaking around for a bit against your app’s estimated usage before you put in the time or money to get your app developed.
Do: Use GCP’s Budget Tools
Naturally, Firebase is an extension of Google Cloud. That means there are tools on the Google Cloud Platform we can take advantage of, and the budget tool is one we definitely want to use. It’s notable that this tool doesn’t cap our spendings but instead, it gives us alerts (at %s we can set) when we might be getting close to our budget.
Not to mention, we get to see how much costs we’ve accumulated for that month so far without having to wait for the bill at the end of the month.
Hidden Truth: Viewing the Console counts as a Database Read
Realtime Database, Firestore, Storage, whatever it is. Every time I open the database in the console, it’s another read closer to the quota. In most cases, this should be negligible. Keep in mind however if you’ve got a pretty large database and you have it open while updates are being made, you might expect to see some changes.
DON’T EVER DO: Cause an Infinite Read Loop while using Blaze
Unless you’ve got access to Bill Gate’s bank account, you want to take some measures while developing or updating your app. If you can deal with the Spark Plan while developing, by all means do so. If 💩 happens, at least all that’ll happen is your quota runs out.
Do: Cut document reads to a minimum
this.users = firestore.collection("users").get()
this.user = firestore.collection("users").doc(uid).get()
var users = this.db.collection("users").valueChanges();
var user = users.pipe(...);
See the difference between these two? One reads twice for some unnecessary reason. You don’t want that. Read the source and gather everything from the source object.
If you’re a company hiring a developer to work on code for your Firebase structures and you know you’re going to have a fair amount of users, don’t scrimp on it. Please. Save yourself some billing stress.
Imagine you have 30000 users. If your code involves 5 reads per user on average, your app requests 150000 reads from Firestore. If you cut it down to a single read per user, that’s down to 30000. Save yourself some money and get drunk tonight.
Blaze Plan is a double-edged sword. Risky it may be, it’s extremely useful in the right hands, and the Firebase Billing Team is always there to help you in case you run into any problems. Looking back at this article, most of this were obvious things most of ya’ll probably already knew. Ah well, so be it.