How To Manage Cost💰 For Your Firebase Cloud Functions?

Himanshu Saraswat
2 min readApr 13, 2020

--

Photo by Josh Appel on Unsplash

Cloud Functions offer a great way to automatically run your backend code in response to events. It allows you to further have larger control over its performance & pricing.

However, with the slightest neglect, you may end up paying a lot 💸 while you were still in development mode.

Let’s first understand why it should be a concern?

In one of my articles, I chose Cloud Functions For Firebase to trigger transactional emails through SendGrid.

The cloud function below was integrated with Angular as the UI framework for the application we built. (Could be any UI framework of your choice)

We happily completed the testing with Postman & deployed it successfully. However, post-integration somehow the client-side app always seems to target the production environment.

Take a note of the function URL

Did we target the production cloud function? Let’s have a look at the logs on Firebase console.

Production cloud function is targeted rather than the one on our local.

Absolutely yes.🙄

The reason here is, your client application is not yet aware of the target URL. If you don’t fix this, you will end up in exhausting your production resources & more importantly you would never be able to debug your cloud function.

Yes, you won’t be able to debug 😉

Solve this now:

Including the below snippet in the constructor of the component responsible for communicating with your cloud function will do the trick.

This will ensure whenever you are in development mode, you target the local cloud function & not the one running in production.

Simple yet effective.

So, What’s the best way to debug cloud functions?

I will take up this topic in the upcoming blog. Stay connected 😇

Head over to HSDevStudio to view the application we created using Cloud Functions live in action.

Hope you have learned something new today. Do appreciate with some claps. 👏👏.

Connect with me on Medium or LinkedIn for consultations.

Happy coding. 💻 #staySafe 😷

--

--

Himanshu Saraswat

MEAN Stack Engineer | Google Cloud Enthusiast | Explore Live Projects @ HSDevStudio.com