Table of contents
1.
Introduction
2.
Cloud Functions for Firebase
2.1.
Key capabilities
2.2.
How does it work?
2.3.
Implementation path
3.
Firebase Extensions
3.1.
Key capabilities
3.2.
How does it work?
3.3.
Implementation path
4.
Frequently Asked Questions
4.1.
What are Cloud Functions in Firebase?
4.2.
Is Cloud Functions free in Firebase?
4.3.
Can I store files in Firebase?
5.
Conclusion 
Last Updated: Mar 27, 2024

Cloud Functions and Extensions in Firebase

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Let's ensure we understand the foundational concepts before delving further into the subjects. Here is a brief introduction if you are unfamiliar with Google Cloud Functions. 

Cloud Functions and Extensions in Firebase

A serverless execution environment for constructing and linking cloud services is called Google Cloud Functions. You can create straightforward, one-purpose functions with Cloud Functions that are linked to events released by your cloud infrastructure and services.     

This article explains the details of Cloud Functions for Firebase and Firebase Extension, in which we talk about how it works, its key capabilities, and its implementation path.

Without further ado, let's get started.

Cloud Functions for Firebase

Cloud Functions for Firebase is a serverless framework that enables you to automatically execute backend code in response to events brought on by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is run in a controlled environment and is stored in Google's Cloud. You don't have to scale and manage your servers.

Key capabilities

Table

How does it work?

💁 Google's servers manage a function as soon as you build and deploy it. If the function is a background, Google's servers will monitor events and perform the function when triggered. Alternatively, you can call the function directly with an HTTP request.

Google adjusts the number of virtual server instances required to run your function quickly as the load rises or falls. Each function operates independently, with its setup and environment.

📁 Lifecycle of a background function

1️⃣ You create a new function by writing code, choosing an event source (such as Cloud Firestore), and specifying the circumstances under which the function should run.
 

2️⃣ When executing your function:

a. Before Cloud Functions generates an Artifact Registry repository (called gcf-artifacts) in your project, the Firebase CLI creates a.zip archive containing the function code, which is then uploaded to a Cloud Storage bucket (prefixed with gcf-sources).

b. The function source is built using Cloud Build when the function code has been retrieved. In the Google Cloud Console, you may see Cloud Build logs.

c. Your new function is released after the container image for the code of the created functions is published to a private Artifact Registry repository in your project (called gcf-artifacts).
 

3️⃣ The function is called when the event generator creates an event that satisfies its requirements.
 

4️⃣ To handle tasks more quickly when a function is busy with many events, Google launches extra instances. Instances are cleaned up when a function is idle.
 

5️⃣ Instances for earlier versions are removed from the Artifact Registry and build artifacts when you update a function by deploying updated code. New instances are then created in their stead.
 

6️⃣ All instances and zip archives are deleted along with any associated build artefacts in the Artifact Registry when a function is deleted. The event provider and the function are no longer linked.

Implementation path

Table

Firebase Extensions

With pre-packaged solutions, Firebase Extensions make it easy to quickly add functionality to your project.

Once deployed, a Firebase Extension responds to HTTPS requests, Cloud Scheduler events, or triggering events from other Firebase products, such as Cloud Firestore or Firebase Cloud Messaging, by carrying out a given job or collection of tasks.

Key capabilities

Table

How does it work?

💁 A Firebase Extension is a piece of code that does a job each time an app- or project-specific event takes place.

Cloud Functions for Firebase are used to create the logic for an extension. An extension's functions specify the event providers and the circumstances under which they are executed (for example, a Cloud Firestore write, an HTTPS request, or a Cloud Scheduler event).

Extensions make use of functions. However, one essential fact between extensions and functions is that an extension relies upon an extension.yaml specification file, which explicitly defines:

✔️ The extension will utilise Google services (APIs).

✔️ Access rights are necessary for the extension to function.

✔️ The resources are unique to the extension that it needs to function.

✔️ The options for the extension's configurable parameters.

An extension may be installed more than once in a project, with each installation having a unique configuration.

📁 Firebase does the following actions when you install an instance of an extension:

1️⃣ You are prompted to enter the configuration values (parameters) for this particular extension instance.
 

2️⃣ Enables the project's extension.yaml file's listed APIs.
 

3️⃣ Assigns the listed access roles to a brand-new service account that will be utilised by this instance of the extension. The extension instance uses the access granted to this service account to run its code.
 

4️⃣ Gives the extension instance the listed resources (for example, a function).

 

Keep in mind that every extension instance that is installed has its service account and resources that are supplied specifically for it.

Implementation path

Table

Frequently Asked Questions

What are Cloud Functions in Firebase?

Using the serverless framework Cloud Functions for Firebase, you may have backend code run automatically in response to events brought on by Firebase features and HTTPS requests.

Is Cloud Functions free in Firebase?

Thanks to its perpetual free tier for invocations, you can try out the platform for free using Cloud Functions. Please be aware that we demand a valid billing account even for free tier usage.

Can I store files in Firebase?

Maintain order using collections. Organize and save stuff according to your preferences. You can quickly and easily upload files using Cloud Storage for Firebase to a Cloud Storage bucket that Firebase provides and manages.

Conclusion 

Congratulations on finishing the blog! We have discussed the details of Cloud Functions for Firebase and Firebase Extension in which we talk about how it works, the Key capabilities, and their implementation path.

We hope this blog has helped you enhance your knowledge of Cloud Functions and Extensions in Firebase. If you'd like to learn more, Check out the following links:

🔥 Firebase: Its features and usage

🔥 Load Balancing in Cloud

🔥 Cloud DNS

 

Please refer to our guided pathways on Code studio to learn more about DSACompetitive ProgrammingJavaScriptSystem Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.

Please upvote 🏆 our blogs 🎈 if you find them helpful and informative!

Happy coding🤗

Live masterclass