The main advantage of Cloud Functions in Google Cloud is that you only need to write your code. Everything else will be done for you; there is no need to manage any infrastructure. Cloud Functions integrates very well within the Google Cloud products ecosystem. Functions listen and respond to various events – for example, when you upload an object to Cloud Storage, the function detects it and can invoke action.
Cloud Functions’ use cases are most likely limited to our creativity, but I’d like to list just a few of the use cases used by Google Cloud customers:
- Webhooks: We can use HTTP triggers to respond to events from other systems such as GitHub, GitLab, Slack, or any software that sends HTTP requests. For example, we can create a Slack command that searches the Google Knowledge Graph API.
- Data processing: This involves listening and responding to Google Cloud Storage events – object creation, change, or deletion. For example, we can perform image processing, video transcoding, or data validation once data has been uploaded to Cloud Storage.
- Lightweight APIs: You can build your applications by combining different cloud functions.
- Mobile backend: You can use the Google Cloud mobile platform application product known as Firebase and write the backend in Cloud Functions.
- IoT: This is the ideal solution for a fleet of devices streaming data into Pub/Sub while invoking Cloud Functions to process, transform, and store data.
Events are, generally speaking, things that happen in your cloud environment. The broadness of Google Cloud services allows users to interact when changes in databases, files, or virtual machines are made by responding to those events.
After an event, we have the option to respond to them. This response is called a trigger. By connecting the two, we can create sophisticated functions that can do some exciting work – fully automated and at scale.
Google Cloud offers two versions of Cloud Functions – 1st and 2nd generation. As anyone could expect, 2nd generation offers multiple improvements over the 1st generation.
To view a detailed comparison of the two generations, go to https://cloud.google.com/functions/docs/concepts/version-comparison#comparison-table.
Another essential feature is that the 2nd generation of Cloud Functions is built on Cloud Run, which was described earlier in this chapter. It also supports Eventarc – Google Cloud’s approach to interacting with various services within Google Cloud.
To learn more about Google Eventarc, go to https://cloud.google.com/eventarc/docs/overview.