Serverless

icon picker
Cloud Run

Cloud Run is a managed compute platform that lets you run containers directly on top of Google's scalable infrastructure.
You can deploy code written in any programming language on Cloud Run if you can build a container image from it. In fact, building container images is optional. If you're using Go, Node.js, Python, Java, .NET Core, Ruby, or a supported framework you can use the option that builds the container for you, using the best practices for the language you're using.
Google has built Cloud Run to work well together with other services on Google Cloud, so you can build full-featured applications.

Services and jobs: two ways to run your code

On Cloud Run, your code can either run continuously as a service or as a job. Both services and jobs run in the same environment and can use the same integrations with other services on Google Cloud.
Cloud Run services. Used to run code that responds to web requests, events, or functions.
Cloud Run jobs. Used to run code that performs work (a job) and quits when the work is done.

Cloud Run services

image.png
A Cloud Run service provides you with the infrastructure required to run a reliable HTTPS endpoint. Your responsibility is to make sure your code listens on a TCP port and handles HTTP requests.

When to use Cloud Run services?

Cloud Run services are great for code that handles requests, events, or functions. Example use cases include:
Websites and web applications: Build your web app using your favorite stack, access your SQL database, and render dynamic HTML pages.
APIs and microservices: You can build a REST API, or a GraphQL API or private microservices that communicate over HTTP or gRPC.
Streaming data processing: Cloud Run services can receive messages from Pub/Sub push subscriptions and events from Eventarc.
Asynchronous workloads: Cloud Run functions can respond to asynchronous events, such as a message on a Pub/Sub topic, a change in a Cloud Storage bucket, or a Firebase event.
AI inference: Cloud Run services with or without GPU configured can host AI workloads such as inference models and model training.


Cloud Run Jobs

If your code performs work and then stops (a script is a good example), you can use a Cloud Run job to run your code. You can execute a job from the command line using the gcloud CLI, , or .

Array jobs are a faster way to run jobs

A job can start one instance to run your code — that's a common way to run a script or a tool. However, you can also start many identical, independent instances in parallel, that is, an array job.
Array jobs are a faster way to process jobs that can be split into multiple independent tasks, as shown here:
image.png

When to use Cloud Run jobs?

Cloud Run jobs are well-suited to run code that performs work (a job) and quits when the work is done. Here are a few examples:
Script or tool: Run a script to perform database migrations or other operational tasks.
Array job: Perform highly parallelized processing of all files in a Cloud Storage bucket.
Scheduled job: Create and send invoices at regular intervals, or save the results of a database query as XML and upload the file every few hours.


Cloud Run allows you to run stateless containers that are automatically scaled up and down based on incoming requests, which can help minimize costs. With Cloud Run, you only pay for the resources you use, and there are no instances to manage or scaling decisions to make. This makes it an ideal option for applications that are not as popular as expected and need to be run cost-effectively.

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.