Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase billing - kill switch

I'm trying to follow this firebase tutorial for setting up a system to disable billing if a quota is exceeded.

https://www.youtube.com/watch?v=Dk3VvRSrQIY

The documents linked in the video description advise that the kill switch can be delayed for a few days before it takes effect:

Note: There is a delay of up to a few days between incurring costs and receiving budget notifications. Due to usage latency from the time that a resource is used to the time that the activity is billed, you might incur additional costs for usage that hasn't arrived at the time that all services are stopped. Following the steps in this capping, example is not a guarantee that you will not spend more than your budget. Recommendation: If you have a hard funds limit, set your maximum budget below your available funds to account for billing delays.

Is it possible that the switch will not activate, when billable activities continue, beyond the quota cap?

Is it possible to utilize a setting that prioritizes the switch above all other activities, so that I can be confident that I won't exceed the cap? I can't find anything in the billing documentation about how this function can be prioritized.

I have seen instances of my own code run off the charts very fast. Others have reported worse financial consequences of mistakes that have happened in less than a few days and misunderstanding how GCP and firebase caps apply.

I want to make sure my kill switch is fired immediately, to shut down billing if the quota is exceeded before I start learning how to use functions.

The firebase documentation includes a warning that if you use a kill switch to stop using firebase when a budget cap is exceeded, as follows:

Warning: This example removes Cloud Billing from your project, shutting down all resources. Resources might not shut down gracefully, and might be irretrievably deleted. There is no graceful recovery if you disable Cloud Billing. You can re-enable Cloud Billing, but there is no guarantee of service recovery and manual configuration is required.

I'm also trying to understand what this warning means. Does anyone have any insight into how the kill switch (youtube.com/watch?v=Dk3VvRSrQIY) works?

I'm trying to investigate what gets irretrievably deleted. Does the datastore get deleted when the kill switch is activated? Is there any opportunity to save data previously stored in a cloud firestore, before the deletion takes place? Is there a way to download the database so that I can keep a backup in this scenario?

like image 685
Mel Avatar asked Nov 07 '22 01:11

Mel


2 Answers

Whilst this doesn't address the question above, this feedback from Google came through overnight.

As discussed in our Pricing FAQ, we currently have no option to cap your Firebase plan usage if ever you may want to upgrade to Blaze plan. However, you may set up alerts so that you are on-track with your spending and notified whenever you meet a threshold limit. For more information about setting budget alerts, you may look into this guide.

In addition to that, you may try using budget notifications to programmatically disable Cloud Billing on a project or try setting a cap on API usage to prevent incurring costs.

For what it's worth, our engineers are aware that many developers would like to be able to cap usages. We are evaluating options for supporting caps on Blaze plan usage; however, we are yet to find out an estimated date for this. I would suggest that you keep an eye out on the Cloud Billing Release Notes or check The Firebase Blog to get the latest updates with Firebase features and services. You may also reach out to our community channels such as Firebase Slack, Firebase Google Groups and Stack Overflow if you want to engage in a discussion with our team. Firebase engineers and experts are very active on those channels, and should be able to answer any questions regarding a way to optimize the cost of your project/s.

To clarify, the kill switch mentioned in Firebase’s YouTube series will function at the time the code has been triggered from your app. The part of Google Cloud’s documentation regarding capping your billing usage where the note says that there is a delay of up to a few days between incurring costs and receiving budget notifications only refers to the charges that hasn’t been reflected yet after capping your billing usage. As mentioned, due to usage latency from the time that a resource is used to the time that the activity is billed, you might incur additional costs for usage that hasn't arrived at the time that all services are stopped. Also, it is recommended that if you have a hard funds limit, you should set your maximum budget below your available funds to account for billing delays.

I've raised this topic to our team and was able to confirm that the kill switch can get activated near real-time (maybe an hour or so); and that your understanding that it is activated by reference to billing is correct. While I do agree that having a near real-time activation of the kill switch is still not ideal for your use-case as you've shared that you've exhausted your free tier within seconds. What I would suggest is reaching out to our engineers from our community channels that I've mentioned from my previous email so that they can help you optimize your project to avoid incurring such cost.

like image 40
Mel Avatar answered Dec 03 '22 20:12

Mel


With the nature of GCP, some features can take time to offload. Cloud functions can be running background tasks, etc. While I didn't see any reference to it taking up to an hour, it's entirely reasonable to see it take about 10 minutes maximum.

If you are seeing high usages within your app when testing, it's most likely you aren't structuring reads and writes ideally. there are several guides and communities available should you want to dive into how to reduce usage on a personal level.

like image 199
DIGI Byte Avatar answered Dec 03 '22 19:12

DIGI Byte