Demo, all content is generated
Question

Firebase budget alert fired but nothing stopped, how do I set a real limit?

Solved · 1101 views · asked by amara_v · edited

I set a $10 budget in Google Cloud for my Firebase project. Got the email at 50%, 90%, 100%... and then it kept going to $31 because of a loop in my app that read the same collection over and over. I thought a budget would stop it?

What I’ve tried

Fixed the loop. Looked for a "hard cap" option in Firebase console, can't find one.

Comment
Was the loop a useEffect without deps, re-subscribing to onSnapshot? That's the classic one. lukas_b · edited

3 answers

Marked as helpful by the asker
sven_fire · edited

Correct, budgets on Google Cloud only alert. There is no built-in hard cap, and billing data lags a few hours, so even an automated stop happens after the fact.

If you want an automatic kill switch, the documented approach is:

  1. Connect the budget to a Pub/Sub topic (Budgets > your budget > "Connect a Pub/Sub topic").
  2. Deploy a Cloud Function subscribed to that topic that, when costAmount > budgetAmount, calls the Cloud Billing API to disable billing on the project.

Understand what that means: detaching billing shuts down everything that needs Blaze (functions, storage beyond free quota, etc.). Your app goes down. That's the trade-off you're choosing.

Cheaper first steps: fix read patterns (listen once, paginate, cache), and set App Check so random scripts can't hammer your DB.

Comment
It was a useEffect loop yes. I'll add the kill switch function, I'd rather be down than broke amara_v · edited
lukas_b · edited

Also set budget alerts at low amounts ($1, $5) so you notice anomalies early. The 50% email of a $10 budget arrived way too late in your case.

Comment
set one at $2 now amara_v · edited
bytebarista · edited

Firestore specifically: a listener that re-subscribes on every render re-reads the whole query each time. Check the Usage tab in the Firebase console per day, a loop shows up as a wall of reads.

Comment