Cloud Functions for Firebase lets you automatically run backend code in
response to events triggered by Firebase features and HTTPS requests. Your code
is stored in Google's cloud and runs in a managed environment. There's no need
to manage and scale your own servers.

Already using Cloud Functions on Google Cloud Platform?
Learn more about how Firebase fits
into the picture.

Integrate across Firebase features using the
Admin SDK
together with Cloud Functions, and integrate with third-party
services by writing your own webhooks.
Cloud Functions minimizes boilerplate
code, making it easier to use Firebase and Google Cloud inside your
function.

Zero maintenance

Deploy your JavaScript or TypeScript code to our servers with one
command from the command line.
After that, Firebase automatically scales up computing resources to match
the usage patterns of your users. You never worry about credentials,
server configuration, provisioning new servers, or decommissioning old
ones.

Keeps your logic private and secure

In many cases, developers prefer to control application logic on the
server to avoid tampering on the client side. Also, sometimes
it's not desirable to allow that code to be reverse engineered.
Cloud Functions is fully insulated from the client, so you
can be sure it is private and always does exactly what you want.

How does it work?

After you write and deploy a function, Google's servers begin to
manage the function immediately. You can fire the function directly with an
HTTP request, or, in the case of background functions, Google's servers will
listen for events and run the function when it is triggered.

As the load increases or
decreases, Google responds by rapidly scaling the number of virtual server
instances needed to run your function. Each function runs in isolation, in its
own environment with its own configuration.

Lifecycle of a background function

The developer writes code for a new function, selecting an event provider (such as Realtime Database), and defining the conditions under which the function should execute.

The developer deploys the function, and Firebase connects it to the selected event provider.

When the event provider generates an event that matches the function's conditions, the code is invoked.

If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.

When the developer updates the function by deploying updated code, all instances for the old version are cleaned up and replaced by new instances.

When a developer deletes the function, all instances are cleaned up, and the connection between the function and the event provider is removed.

In addition to listening for events with a background function, you can call
functions directly with an HTTP request or a
call from the client.