When Google Cloud Functions is the right choice, and when it is not

Google Cloud Functions runs one piece of code when something triggers it, with no server to keep alive. The useful question is when it is the right unit of work and when it becomes the wrong one.
That question comes up in four places: where a function earns its place, where it turns into an architecture problem, when a Cloud Run service is the better fit, and what you have to arrange before it handles real traffic. Google’s documentation calls it Cloud Run functions these days. Only the name changed and the product is the same.
Where a function earns its place
In a data platform, three uses come back regularly.
The first is picking up a file that a supplier drops in a Cloud Storage bucket. The function runs when the file lands, so nothing has to check an empty folder all day. The second is enriching a message on its way through Pub/Sub. One message in, one message out, and the code stays small enough to read in a minute. The third use is calling an external API on a schedule, which is usually where application integration on Google Cloud starts.
These three have the same shape: one job, one trigger, and nothing that has to keep running in between. That is what a function is built for, and it is the cheapest way to run it.
Where a function becomes the wrong architectural choice
Four situations turn a function into a problem:
Heavy transformation is the first common problem. Reshaping a full table belongs in the warehouse, where the data already is. Pushing it into a function means paying for processing in two places, and for moving the data between cost-efficient data platforms.
An application with several routes is the second issue. A function has one entry point. As soon as a second and a third are bolted on, you are maintaining an application inside something that was never meant to be one.
Work that runs long is the third problem. On the current generation, a function times out after 60 minutes on an HTTP trigger and after 9 minutes on an event trigger. A job that needs more time stops halfway. A retry starts the job again from the beginning and runs into the same limit.
Shared state is the fourth difficulty. A function forgets everything the moment it stops, so run two knows nothing about run one. If the second run needs to know what the first one did, you have to write that somewhere outside the function and read it back at the start. A Cloud Run service stays running between requests, so it can hold on to that information for as long as it is up. That is easier than rebuilding it on every run, though anything you cannot afford to lose still belongs in a database.
Google Cloud Functions or a Cloud Run service
A function is the right unit when the code has one job and one trigger. A Cloud Run service is the right unit as soon as there are several routes, shared state, or a container the team already maintains as part of cloud native development.
Since the rename to Cloud Run Functions, both run on the same infrastructure. The choice is about the shape of your code rather than between two platforms. That makes it easier to change your mind later: code that outgrows a function can move to Cloud Run without leaving the platform. The table sets the two side by side.
| Google Cloud Functions | Cloud Run service | |
|---|---|---|
| Unit of deployment | One piece of code with one entry point | A container the team builds and maintains |
| Typical trigger | One HTTP endpoint or one platform event | Any HTTP route, and events through Eventarc |
| Best fit | A single job that runs on a trigger and then stops | An application with several endpoints or its own dependencies |
| Where it becomes a problem | Several routes, shared state, or a build the team wants to control | One small job, where the container adds work without adding value |
What has to be settled before a function carries production traffic
Four checks come before a function handles real traffic. The first is which service account it uses and how far that account can reach. The second is what the function does when it has to try again. The third is where the logs end up, and the fourth is who gets the call when something fails.
The first check is worth a separate look. Permission mistakes in Google Cloud IAM usually start with an account that could reach more than it needed, and a function is an easy place to hand that out by accident.
Retry behaviour is the check that gets skipped most often. The other three announce themselves: a missing permission fails on day one, and missing logs are noticed the first time somebody goes looking. Retries give no signal at all. Everything looks fine until somebody finds the same record twice.
Here is how that happens. The function writes a record to the warehouse. The writing succeeds, but the confirmation never reaches the function. The function assumes it failed and writes the same record again. Nothing broke, no alert went off, and the warehouse now holds that record twice. Decide in advance what should happen on a second attempt, and let the function check whether the record is already there before it writes.
Logs on their own do not warn anyone. Put an alert on the error rate and on the number of messages that end up undelivered, and name the person who receives it. Without that last step, the first three checks only record what went wrong. Are you building this into a data platform or a custom application and want a second pair of eyes on the service account, the retries and the alerts? Get in touch and we will look at it with you.
Why the documentation says Cloud Run functions
Google renamed Google Cloud functions on 21 August 2024. Only the name changed. Your existing functions keep running, and the APIs, gcloud commands and Terraform modules you already use still work, so there is nothing to migrate. Google Cloud functions is the term used here, with Cloud Run functions as the current official name.
Frequently asked questions about Google Cloud functions
What is a cold start and how much does it matter?
A cold start is the wait while a new instance is created for a request that finds none ready. Minimum instances keep one or more warm, and concurrency lets one warm instance handle several requests at once.
Can a function reach a database on a private network?
A function reaches a database on a private network through direct VPC egress, which attaches it to your own VPC. This needs a second generation function, so a first generation function has to be upgraded before the route is available.
Do first generation functions still work?
First generation functions still work and stay available as Cloud Run functions (1st gen), with their APIs, gcloud commands and Terraform modules supported. Google recommends the current generation for new work. Check the documentation before assuming any end date.
What happens to a function when the source system is down?
When the source system is down, the event is offered again later. Decide how often the function should try, and where a message goes once it keeps failing, so it lands in a dead letter topic, where it can be inspected and replayed, rather than only in the logs.
