Whether you're just starting out developing your app or you have a full-blown
production app, you want to make sure you understand your costs and how to avoid
surprise bills.

If you haven't already, check out the [Firebase pricing
plans](https://firebase.google.com/docs/projects/billing/firebase-pricing-plans) to understand how billing
works for Firebase.

> [!IMPORTANT]
> **Important:** **Firebase pricing plans apply to the entire project, not just to
> individual apps registered in the project.** When you're determining which pricing plan is right for you, consider the usage from *all the apps* registered in the same project. Learn more about [best practices](https://firebase.google.com/docs/projects/dev-workflows/general-best-practices.md.txt) for when to add multiple apps to the same Firebase project.

[Video](https://www.youtube.com/watch?v=EoLp0WoUkoA)

This page guides you through important aspects of understanding and monitoring
your usage and spend levels, including:

- [Testing your code](https://firebase.google.com/docs/projects/billing/avoid-surprise-bills.md.txt#test-code)
- [Viewing your usage and spending levels](https://firebase.google.com/docs/projects/billing/avoid-surprise-bills.md.txt#view-usage-and-spending-levels)
- [Setting up budget alerts and spend caps](https://firebase.google.com/docs/projects/billing/avoid-surprise-bills.md.txt#set-up-budgets)

*** ** * ** ***

## Test your code

Testing your code before deploying to production is a great idea for many
reasons, like catching errors that might cost you significant amounts of money.
As you're building the infrastructure for your app, **we highly recommend first
testing locally using the [Firebase Local Emulator Suite](https://firebase.google.com/docs/emulator-suite.md.txt)**.

The Local Emulator Suite allows you to run instances of Cloud Functions,
Cloud Firestore, the Realtime Database and more all locally on your desktop machine.
This not only makes it easier for you to quickly iterate on new functionality ---
particularly Cloud Functions --- but it also ensures that you don't incur any
Firebase costs that might result from testing against services in production.

As you're testing, check for these common causes of exceeding expected usage and
spend:

- Forgetting to add a limit to a database query with millions of results

- Combinations of Cloud Functions that cause excessive fan-out workloads
  or even infinite loops

<br />

*** ** * ** ***

<br />

## View your usage and spending levels

You need to know what normal usage patterns look like for your app and make sure
you're staying within thresholds important to you.

> [!NOTE]
> Most Firebase products provide product-specific documentation about usage, quotas, and pricing. They also often provide usage-to-billing examples for the product. Visit a product's section in the Firebase documentation to find this type of information.
>
> For example, here's documentation to
> [understand billing for Cloud Firestore](https://firebase.google.com/docs/firestore/pricing.md.txt).

### View individual product usage

You can view individual product usage in the "Usage" tab for many products in
the Firebase console.

- You can view specific date ranges in these dashboards.

- Product-level dashboards are available for
  [Authentication](https://console.firebase.google.com/project/_/authentication/usage?useAutoProject=true)
  and all the infrastructure products:
  [Realtime Database](https://console.firebase.google.com/project/_/database/usage?useAutoProject=true),
  [Cloud Firestore](https://console.firebase.google.com/project/_/firestore/usage?useAutoProject=true),
  [Cloud Storage](https://console.firebase.google.com/project/_/storage/usage?useAutoProject=true),
  [Cloud Functions](https://console.firebase.google.com/project/_/functions/usage?useAutoProject=true),
  and [Hosting](https://console.firebase.google.com/project/_/hosting/usage?useAutoProject=true).

### View overall project usage

You can view your project's overall usage in the
**Settings** \>
[**Usage and billing** dashboard](https://console.firebase.google.com/project/_/usage?useAutoProject=true)
of the Firebase console.

- You can view your monthly usage and how your usage levels are
  measuring up to the allocated no-cost usage quota.

- Click into any product to review a daily summary of usage and how it
  measures up to the allocated no-cost usage quota.

Remember that each product has different usage quotas and thus different
timelines, for example:

- Cloud Firestore and Cloud Storage usage are calculated daily.

- Cloud Functions usage is calculated monthly.

<br />

*** ** * ** ***

<br />


## Set up budgets

You can control your costs and avoid surprises on your bill by creating budgets
for Google Cloud Billing. ***Budgets*** are general monetary amounts
that you plan on spending each month, and they can either be
***alerts-only budgets*** or ***spend cap budgets***.

#### Alerts-only budgets

- If spending reaches set thresholds for your budget,
  then Cloud Billing ***sends email notifications***.

- Note the following:

  - Budget alerts *do **not*** pause services. They're intended to help you
    monitor your costs and to alert you so that you can take action,
    if needed. For example, you might consider
    [using budget notifications to disable billing on the project](https://docs.cloud.google.com/billing/docs/how-to/disable-billing-with-notifications).

  - When you upgrade to the Blaze pricing plan in the
    Firebase console, you're automatically prompted to set up an
    alerts-only budget.
    You can also manually
    [set up alerts-only budgets](https://firebase.google.com/docs/projects/billing/budget-alerts.md.txt) in the
    Google Cloud console.

#### Spend cap budgets

- If spending reaches set thresholds for your budget *for a specific service* ,
  then Cloud Billing ***sends email notifications***.

- If spending reaches 100% of your budget for that service,
  then Cloud Billing ***pauses that service for the rest of the month***.

- Note the following:

  - Spend caps budgets are only available for the following Firebase services:
    Firebase AI Logic, Firebase App Hosting, Cloud Functions for Firebase, and Firebase Extensions.

  - You can manually
    [set up spend cap budgets](https://firebase.google.com/docs/projects/billing/spend-caps.md.txt) in the
    Firebase console or Google Cloud console.

  <br />

> [!NOTE]
> [All Firebase
> projects are actually Google Cloud projects](https://firebase.google.com/docs/projects/learn-more#firebase-cloud-relationship) behind the scenes, which means billing is shared across Firebase and Google Cloud and you can view the same project in both the Firebase console and the Google Cloud console.

## Next steps

- Set up [budget alerts](https://firebase.google.com/docs/projects/billing/budget-alerts.md.txt) and
  (if applicable) [spend caps](https://firebase.google.com/docs/projects/billing/spend-caps.md.txt).

- Consider using
  [budget notifications to programmatically disable Cloud Billing on a project](https://docs.cloud.google.com/billing/docs/how-to/disable-billing-with-notifications).

- Visit
  [Set up advanced billing alerts and logic](https://firebase.google.com/docs/projects/billing/advanced-billing-alerts-logic.md.txt)
  to learn how to do the following:

  - Use Cloud Monitoring to create more sophisticated alerts for billing
    and usage, including custom alerts that send notifications to other
    mediums, like Slack.

  - Create additional billing logic based on Google Cloud Pub/Sub.