Skip to content

Cloud Functions as Versatile Building Blocks

Google Cloud

What are Cloud Functions?

Cloud Functions are a Google Cloud service that allows the user to run custom code in a managed environment, that is, an environment where you don’t have to worry about provisioning a machine, installing the required runtime, scaling up and down according to the computing requirements, and updating the underlying software.

Only the code needs to be provided and can be packaged and deployed in various ways, such as the g-cloud command tool, or infrastructure as code tool.

An important highlight is the on-demand pricing since the service features a pay-for-what-you-use schema, where the billing is tied to the execution time of the process instead of paying for an idle virtual machine.

Cloud Functions can be seen as useful building blocks that can solve complex personalised requirements in a simple efficient way, while also favouring development and deployment speed.

What are cloud functions useful for?

Whenever Cloud Functions are considered, an on-demand single execution context is most likely present, thus, they represent prime candidates for event-driven processes, such as Slack notifications, alerts on important events, ad-hoc computations in a complex pipeline, and even transformations on an input file prior to starting a workflow.

How can you integrate cloud functions in your infrastructure?

Each call to a cloud function is an instance of an isolated, stateless environment, with no concurrency involved between calls. The platform handles the creation of instances according to the number of requests so that the code remains simple.

The most intuitive way to trigger a Cloud Function is through an HTTP call which is fully supported. Additionally, there are several triggers that allow the user to set up cloud functions as part of a workflow, an independent process started through an API call, or as part of a bigger process, triggered by an external event such as a file being modified, new data came into the pipeline or user actions in their mobile app.

Synergy with the GCP ecosystem

Simplicity sometimes implies limitations, in the sense of lacking approaches to more complex use cases that require persistent state, security, visibility and integration inside a larger enterprise ecosystem.

Cloud Functions address this by having a seamless integration with the rest of the cloud services provided by GCP. It is possible to use Secret Manager to securely access sensitive credentials, call the different persistent storage APIs such as Firestore or Cloud Storage, implement event-driven approaches using PubSub, and rely on Eventarc to write custom code that does personalised processing depending on the type of the event. All of this while having clear logs and traces to monitor the usage and gather useful metrics.

How can I learn more?

This article is a part of a greater series centred around the technologies and themes found within the first edition of the TechRadar by Devoteam. To read further into these topics, please download TechRadar by Devoteam.