Operation
Developing Serverless Applications on Google Cloud with Cloud Run
Cloud Run has come a long way since it was first introduced as an add-on for Google Cloud Anthos (Google’s former app modernisation platform).
It is now a standalone platform capable of handling various types of serverless workloads, including web services, background jobs, and more. However, because Cloud Run features different components for handling these workloads, navigating it can be challenging.
Finding the ideal solution for your workload and getting the most out of this platform is no easy task. That’s why, in this article, we’ll take a detailed look at Cloud Run. By the end, you’ll know exactly what Cloud Run is and which workloads are well-suited for it.

What are the key features of Cloud Run?
As Google Cloud's serverless container execution platform, Cloud Run offers the following key features:
It is language-agnostic
Cloud Run allows you to deploy code in any language, provided you can package it into a container. However, building a container image manually is entirely optional. More specifically: if your code is written in Node.js, Python, Go, or Ruby, Cloud Run offers an option that builds the container for you.
Fast autoscaling
As incoming requests to your service increase, Cloud Run automatically adds instances to meet these new demands. Likewise, it scales down instances when traffic decreases. It can even scale to zero, meaning no instances run when your app is not in use. This makes Cloud Run cost-efficient, as you only pay when the app is actually being used.
GPUs for AI workloads (in preview)
Recently, Google Cloud announced that Cloud Run now supports NVIDIA L4 GPUs. This opens up Cloud Run to more resource-intensive use cases, such as:
Building custom chatbots using lightweight models, such as Google's open-source model Gemma or Meta's Llama 3.
Deploying generative AI models fine-tuned with your enterprise data.
Compute-heavy services such as 3D rendering.
NVIDIA GPUs give Cloud Run the capacity to handle AI inference workloads, particularly for applications requiring real-time processing.
When Cloud Run launched, it only supported stateless containerised workloads that could be invoked via HTTP requests. This was the only way to run code on it. Now that Cloud Run is a platform, it supports more types of workloads.
Ways to run your code on Cloud Run
Cloud Run offers you three ways to run code on it. These include:
Cloud Run services.
Cloud Run jobs.
Cloud Run functions.
Each of these methods is suited to a different type of workload.
1. Cloud Run services
This is what most people think of when talking about Cloud Run, as it was initially the only way to run code on this platform. A Cloud Run service is used to run code that responds to web requests or events.
With services, Cloud Run provisions the infrastructure required to run a reliable HTTPS endpoint. You must ensure that your code listens on a TCP port and handles HTTP requests.
With that in mind, what workloads are well-suited for Cloud Run services? Here are a few examples:
Websites and web applications.
Microservices and APIs – This includes REST, GraphQL, and gRPC APIs.
Streaming data processing with Pub/Sub.
Cloud Run services come with all of Cloud Run's built-in features, such as support for NVIDIA GPUs, autoscaling, and so on. Regarding autoscaling, each Cloud Run service features an internal load balancer. This load balancer is responsible for adding and removing instances to meet demand.
Manual scaling of Cloud Run services (in preview)
By default, Cloud Run services automatically scale your instances based on demand. Now, manual scaling is also supported. This is useful if you want to set a specific number of instances or prevent Cloud Run from scaling down to zero.
2. Cloud Run jobs
Some workloads are not suited to run as Cloud Run services. For example, those that do not listen for HTTP requests and whose containers run until completion.
For these types of workloads, Cloud Run offers the Cloud Run jobs extension. Cloud Run jobs are suited for code that carries out a task and then stops, such as a script to perform a database migration.
They are also suitable for:
Background processing – for instance, if you run an e-commerce shop and customers have abandoned their baskets, you can use Cloud Run jobs to send email campaigns for those abandoned baskets.
Batch data processing – particularly the extraction phase of ETL.
How it works
When you run a job, Cloud Run automatically starts the instances required for full execution. Once complete, Cloud Run’s autoscaling feature scales the job back down to zero until the next run. You do not need to manually shut down the instances once the job is finished.
Since these jobs do not serve HTTP requests, how can you run them? Google Cloud offers several ways to do this depending on your needs. To run a Cloud Run job directly, you can use:
Google Cloud Console - Here, you select the job you wish to run on your Cloud Run jobs page and click "Run".
Google Cloud CLI - Use the gcloud run jobs execute command to start the job.
You can also schedule a job using Cloud Scheduler. This is ideal for regular tasks such as generating reports or backups.
Finally, you can integrate your Cloud Run job with other Google Cloud services such as Workflows, Pub/Sub, and Cloud Storage. This way, specific activities, for example when Pub/Sub publishes a message to a particular topic, will trigger the Cloud Run job.
3. Cloud Run functions
What if you don’t want to deploy an entire service or job on Cloud Run, but just a snippet of code? For this, you can use Cloud Run functions. Cloud Run functions offer a simple way to run small, single-purpose functions directly on Cloud Run.
You deploy functions as services on Cloud Run and configure them to respond to HTTP(S) requests or events from Pub/Sub, Eventarc, and so on. These functions must be written in a supported language such as Node.js, Python, Go, etc.
This is similar to running a Cloud Run service, with the difference being that you don’t need to build a container image here. You only provide the source code. The function runs as a service and automatically scales based on events.
Cloud Run functions are suitable for various use cases, such as:
Deploying lightweight APIs and webhooks.
Processing raw data from Pub/Sub and enriching it with additional information.
Analysing audit logs for suspicious activities.
In short: Cloud Run functions are ideal for writing isolated business logic.
Update: Cloud Functions (2nd gen) is now Cloud Run functions
Google has merged the Cloud Functions infrastructure with Cloud Run to form Cloud Run functions. Now, Cloud Run functions users have access to the latest Cloud Run features, including NVIDIA GPUs for AI workloads.
As a result of this unification, functions are now a deployment option within Cloud Run. You can write functions and deploy them on Cloud Run infrastructure. Although much has changed, Cloud Run functions retains most of its previous capabilities, such as support for existing APIs and gcloud commands.
Cloud Run integrations within Google Cloud
Cloud Run is tightly integrated with the broader Google Cloud ecosystem. Let's look at some of the most important integrations you'll use alongside Cloud Run.
Data storage
It is hard to imagine a web app that does not need to store data. That's why Cloud Run integrates with so many data solutions in Google Cloud, including:
Cloud SQL - A fully managed relational database service for MySQL and PostgreSQL.
AlloyDB - For demanding PostgreSQL workloads.
Cloud Storage - For storing unstructured data.
And more.
Cloud Tasks
You can offload tasks from your app outside of a user request by using Cloud Tasks. Let's say a user places an order in your app. Instead of processing the payment synchronously and sending a confirmation email, Cloud Tasks allows you to handle this in the background. This prevents your app from slowing down.
Secret Manager
With Secret Manager, you can securely store your database passwords, API keys, and certificates. This helps ensure that your sensitive data does not fall into the wrong hands.
Cloud Run pricing
Cloud Run pricing is based on the resources your containers consume. You are only billed for the time your instances are actively processing requests (for services) or running jobs.
You are also charged per million requests, for CPU and memory allocation, and for data transferred out of your instance. What you can take away from this is that Cloud Run has a dynamic pricing model, which you will understand once you have specified the resources you use. For further guidance, you can visit the Cloud Run pricing page.
Summary
Cloud Run makes it easy for developers to run containers directly on Google Cloud's scalable infrastructure. It is a serverless solution, meaning it takes care of provisioning and managing the infrastructure for developers so they can focus on code.
Although it began as an add-on for Anthos, Google has worked to develop it into a standalone platform equipped with features to handle different types of workloads. On top of that, tight integration into the Google Cloud ecosystem means more features and a better deployment experience for developers.



