Prev Next

Cloud / Google Cloud Run Interview questions

Last updated

1. What is Google Cloud Run? 2. What are the main resource types in Cloud Run? 3. What is a revision in Cloud Run? 4. What is the container contract for Cloud Run services? 5. What is the purpose of the PORT environment variable in Cloud Run? 6. How do you deploy a container image to Cloud Run? 7. What are Cloud Run jobs? 8. What is request concurrency in Cloud Run? 9. What is a cold start in Cloud Run? 10. What is the purpose of min instances in Cloud Run? 11. What is the purpose of max instances in Cloud Run? 12. How do you make a Cloud Run service publicly accessible? 13. What is the purpose of the roles/run.invoker role? 14. What is the request timeout in Cloud Run? 15. How do you deploy source code directly to Cloud Run? 16. What is the purpose of a service account in Cloud Run? 17. How do you use environment variables in Cloud Run? 18. Which languages and runtimes does Cloud Run support? 19. Does Cloud Run support WebSockets and gRPC? 20. What are Cloud Run worker pools? 21. What is the difference between Cloud Run and Cloud Functions? 22. When would you choose Cloud Run over GKE? 23. What is the difference between Cloud Run services and jobs? 24. How does Cloud Run autoscaling work? 25. How does request-based billing differ from instance-based billing in Cloud Run? 26. How can you reduce cold start latency in Cloud Run? 27. What is the difference between first and second generation execution environments? 28. How does traffic splitting work in Cloud Run? 29. How do you perform a canary deployment in Cloud Run? 30. How do you roll back a bad release in Cloud Run? 31. How do you secure service-to-service calls in Cloud Run? 32. How do you manage secrets in Cloud Run? 33. How does Cloud Run connect to resources inside a VPC? 34. What is the difference between Direct VPC egress and a Serverless VPC Access connector? 35. How do you connect a Cloud Run service to Cloud SQL? 36. How do ingress settings control access to Cloud Run? 37. When should you put a load balancer in front of Cloud Run? 38. What happens when Cloud Run reaches max instances? 39. Why do Cloud Run requests return 504 errors? 40. How do you troubleshoot a Cloud Run container that fails to start? 41. How do you run background or event-driven workloads on Cloud Run? 42. How does Cloud Run handle container shutdown and SIGTERM? 43. How does file storage work in Cloud Run? 44. What are startup and liveness probes in Cloud Run? 45. How do you tune concurrency and CPU for a Cloud Run service? 46. How can you optimize Cloud Run costs? 47. How do you monitor a Cloud Run service? 48. Explain the lifecycle of a request handled by Cloud Run? 49. Explain the deployment flow from source code to a live Cloud Run revision? 50. How do you implement multi-region high availability on Cloud Run?

1. What is Google Cloud Run?

Cloud Run is a fully managed serverless platform on Google Cloud that runs containers without you managing servers or clusters. You give it a container image (or source code) and it takes care of provisioning, HTTPS endpoints, scaling and patching of the underlying infrastructure.

It scales with traffic, including down to zero instances when nothing is calling the service, and you are billed only for the resources your code actually uses.

The unit of deployment is a standard container, so any language, framework or binary works as long as it follows the container contract. Cloud Run offers services for HTTP workloads, jobs for run-to-completion tasks and worker pools for continuous background processing.

Take quiz
What does Cloud Run deploy and run for you?
Kubernetes clusters that you size manually
Virtual machines that you patch yourself
Only Java WAR files
Stateless containers with automatic scaling and HTTPS
What can an idle Cloud Run service scale down to?
Zero instances
The size of a node pool
One instance per region
Two instances for availability

2. What are the main resource types in Cloud Run?

Cloud Run has three workload types, each for a different execution pattern.

Resource Triggered by Typical use
Service HTTP, HTTP/2, gRPC, WebSockets or events routed over HTTP APIs, web apps, webhooks
Job Manual run, schedule or workflow Batch processing, migrations, report generation
Worker pool No request; pulls work continuously Queue or Kafka consumers, long-running background workers

Services get a stable run.app URL and scale on incoming requests. Jobs run tasks until the container exits. Worker pools have no HTTP endpoint and keep instances running to process work from a queue or stream.

Take quiz
Which Cloud Run resource type has no HTTP endpoint and pulls work from a queue?
Service
Worker pool
Traffic tag
Revision
Which resource type is the right fit for a nightly database migration that exits when finished?
Ingress rule
Service
Job
Worker pool

3. What is a revision in Cloud Run?

A revision is an immutable snapshot of a service: the container image plus its configuration, such as environment variables, memory, CPU, concurrency, timeout and service account. Cloud Run creates a new revision every time you deploy a new image or change any of those settings.

Revisions are named like my-service-00007-abc and each one can receive a share of traffic. Because they never change after creation, you can send traffic back to an older revision for an instant rollback.

Revisions that receive no traffic do not run instances, so keeping a few old ones around costs nothing in compute.

Take quiz
What happens when you change the memory setting of a Cloud Run service?
Nothing until you restart the cluster
The service is deleted and recreated
A new revision is created
The running revision is edited in place
Why are revisions useful for rollbacks?
They are immutable, so traffic can return to an old one
They freeze all other services
They back up the Dockerfile to Git
They keep a running copy of the database

4. What is the container contract for Cloud Run services?

The container contract is the set of rules your container must follow to run correctly on Cloud Run. For services, the main ones are:

  • Listen for requests on 0.0.0.0 at the port in the PORT environment variable (not on 127.0.0.1).
  • Respond within the configured request timeout, otherwise the request ends with a 504.
  • Be stateless, since instances start and stop at any time and local files vanish with them.
  • Do not terminate TLS yourself; Cloud Run handles HTTPS and forwards plain HTTP to the container.

Jobs follow a different rule: the container must exit when the work is done, with exit code 0 meaning success.

Take quiz
On which address must a Cloud Run service container listen?
Any unix socket in /tmp
127.0.0.1 on port 80 only
Port 443 with its own certificate
0.0.0.0 on the port from PORT
What must a Cloud Run job container do when its work is complete?
Return an HTTP 200 forever
Exit the process
Write a revision file to disk
Keep listening on PORT

5. What is the purpose of the PORT environment variable in Cloud Run?

Cloud Run injects PORT into the ingress container to tell your app which port to listen on. The default value is 8080, and you can change it with --port at deploy time.

Your code should read the variable instead of hard-coding a number. If the app listens somewhere else, Cloud Run cannot reach it and the revision fails its startup check.

import os
from flask import Flask
app = Flask(__name__)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

Take quiz
What is the default value of PORT in Cloud Run?
443
3000
80
8080
What happens if your app listens on a port other than the one Cloud Run expects?
The request is retried on a new region
Cloud Run auto-detects the new port
The revision fails its startup check
Traffic is routed to port 80 instead

6. How do you deploy a container image to Cloud Run?

Push the image to a registry such as Artifact Registry, then deploy it with gcloud run deploy. You can also use the Cloud Console, Terraform or the Cloud Run Admin API.

gcloud run deploy orders-api \
  --image us-docker.pkg.dev/my-proj/apps/orders-api:1.4.0 \
  --region us-central1 \
  --memory 512Mi \
  --set-env-vars APP_ENV=prod

The command creates a new revision, waits for it to pass its startup check and then routes traffic to it. The output prints the service URL.

Take quiz
Which gcloud command deploys a prebuilt image to Cloud Run?
gcloud container clusters deploy
gcloud run deploy --image
gcloud app deploy --image
gcloud compute instances create
What does a successful deploy produce for the service?
A new revision that receives traffic
A new VPC network
A new Cloud SQL replica
A new GKE node

7. What are Cloud Run jobs?

A Cloud Run job runs a container to completion instead of serving requests. A job is made of one or more tasks, and each task runs one container instance until it exits.

You control the number of tasks with --tasks, how many run at once with --parallelism, and failure handling with --max-retries and --task-timeout. Each task can read CLOUD_RUN_TASK_INDEX and CLOUD_RUN_TASK_COUNT to pick its slice of the data.

Jobs can be started manually, from Cloud Scheduler or from Workflows. They suit batch work like data imports, nightly reports and database migrations.

Take quiz
Which variable tells a Cloud Run job task which shard of the work to process?
CLOUD_SQL_INSTANCE
K_REVISION
PORT
CLOUD_RUN_TASK_INDEX
Which flag limits how many tasks of a job run at the same time?
--parallelism
--min-instances
--max-instances
--concurrency

8. What is request concurrency in Cloud Run?

Concurrency is the maximum number of requests a single container instance handles at the same time. The default is 80 and the maximum is 1000, set with --concurrency.

When every instance is at its limit, Cloud Run starts more instances. Higher concurrency means fewer instances for the same traffic, which usually lowers cost, but your code must be safe for parallel requests.

Set it to 1 if the app is not thread-safe or each request needs most of the CPU.

Take quiz
What is the default concurrency of a Cloud Run service?
10
1000
80
1
When would you set concurrency to 1?
When the service has no environment variables
When code is not safe for parallel requests
When using a custom domain
When you want the cheapest possible bill

9. What is a cold start in Cloud Run?

A cold start is the extra latency a request sees when Cloud Run has no ready instance and must start one. The delay covers pulling the image layers, starting the container, running your initialization code and passing the startup check.

Cold starts happen after scale-to-zero, during traffic spikes that need new instances and after a new revision is deployed. Warm instances answer immediately.

Typical fixes are minimum instances, startup CPU boost, smaller images and lazy initialization of heavy dependencies.

Take quiz
When does a request pay a cold start penalty?
Whenever concurrency is above 1
When Cloud Run must start a new instance to serve it
Only when the region changes
Only on the first deploy ever
Which of these is part of a cold start?
Resizing the VPC subnet
Rotating the service account key
Running your application initialization code
Rebuilding the Dockerfile

10. What is the purpose of min instances in Cloud Run?

--min-instances keeps a set number of instances ready even when there is no traffic. The default is 0, which allows scale-to-zero.

With a minimum of 1 or more, the first request does not wait for a container to start, which removes most cold starts for latency-sensitive APIs.

The trade-off is cost: idle minimum instances are still billed, at a lower idle rate under request-based billing, so use them only on services where latency matters.

Take quiz
What is the default value of min instances?
5
1
100
0
What is the main cost of setting min instances above zero?
Idle instances are still billed
Revisions cannot be rolled back
Requests are limited to one region
Concurrency is forced to 1

11. What is the purpose of max instances in Cloud Run?

--max-instances caps how many instances a service or revision can scale out to. The default limit is 100 and it can be raised through quota.

A cap protects things behind the service that cannot scale as fast, such as a Cloud SQL database with limited connections, and it puts a ceiling on spend if traffic or a bug creates a flood of requests.

If traffic needs more capacity than the cap allows, extra requests wait briefly and then fail with a 429.

Take quiz
Why would you lower max instances on a service that uses Cloud SQL?
To enable scale-to-zero
To stop it from exhausting database connections
To make revisions immutable
To disable HTTPS
What status code is typical when requests exceed the allowed capacity?
301
204
418
429

12. How do you make a Cloud Run service publicly accessible?

Grant the roles/run.invoker role to allUsers. The deploy flag --allow-unauthenticated does this for you.

gcloud run services add-iam-policy-binding my-service \
  --member=allUsers --role=roles/run.invoker --region=us-central1

Without that binding, every request needs a valid Google-signed identity token. Note that an organization policy for domain-restricted sharing can block allUsers bindings, and the ingress setting must also allow traffic from the internet.

You can check the current state with gcloud run services get-iam-policy my-service. If allUsers is missing from the roles/run.invoker binding, the service is private. To close it again, remove that binding and callers will get 403 Forbidden unless they send a valid identity token.

Take quiz
Which IAM member makes a Cloud Run service callable without authentication?
The default compute account with roles/editor
A group with roles/run.admin
allUsers with roles/run.invoker
allAuthenticatedUsers with roles/viewer
What blocks a request that has no identity token on a private service?
Missing run.invoker permission, returning 403
A missing Dockerfile
A lower max instances value
A full Artifact Registry

13. What is the purpose of the roles/run.invoker role?

roles/run.invoker gives a principal permission to call a Cloud Run service or job, and nothing else. It does not allow deploying, editing or reading configuration.

You grant it to the callers: a front-end service account, a Pub/Sub push subscription, a Cloud Scheduler job or allUsers for public services.

Deploying is covered by roles/run.developer or roles/run.admin, which keeps caller access and deploy access separate.

A common mistake is giving a caller roles/run.admin just to make requests work. That grants far more than needed. Scope run.invoker to a single service when possible rather than the whole project, so a leaked credential can only call what it was meant to call.

Take quiz
What does roles/run.invoker allow?
Deploying new revisions
Managing Artifact Registry repositories
Calling a Cloud Run service
Editing the VPC
Which principal typically needs run.invoker for a push subscription?
The Docker daemon
The load balancer only
The Cloud Build trigger
The subscription's service account

14. What is the request timeout in Cloud Run?

The request timeout is the longest time Cloud Run waits for your container to return a response. The default is 300 seconds (5 minutes) and it can be raised up to 3600 seconds with --timeout.

The clock includes container startup time when the request triggers a cold start. If the response is not sent in time, Cloud Run ends the request and returns 504.

Long work such as exports or large file processing is better moved to a job or queued with Cloud Tasks than stretched over a very long request.

Take quiz
What is the default request timeout for a Cloud Run service?
300 seconds
60 minutes
10 seconds
30 seconds
Which status does a client see when a request exceeds the timeout?
401
504
302
404

15. How do you deploy source code directly to Cloud Run?

Run gcloud run deploy --source . from your project folder. Cloud Run uses Cloud Build to turn the code into a container, stores the image in Artifact Registry and deploys it.

If the folder has a Dockerfile, it is used. Otherwise Google Cloud buildpacks detect the language (Go, Node.js, Python, Java, .NET, Ruby or PHP) and build the image for you.

This is handy for prototypes. For production, teams usually build in a CI pipeline and deploy a tagged image so every release is traceable.

Take quiz
What turns source code into an image during a source deploy?
Pub/Sub
Cloud Build with buildpacks or a Dockerfile
Cloud DNS
Cloud Scheduler
Which file takes priority in the source folder when building?
Dockerfile
app.yaml
terraform.tfvars
README.md

16. What is the purpose of a service account in Cloud Run?

A Cloud Run revision runs as a service account, and that identity decides what Google Cloud APIs the code can call: Cloud Storage, Secret Manager, Pub/Sub, Cloud SQL and so on.

By default it is the Compute Engine default service account, which often holds broad permissions. Create a dedicated service account per service and grant only the roles it needs, then set it with --service-account.

The same identity is used to fetch ID tokens when the service calls other private Cloud Run services.

Take quiz
Why create a dedicated service account for each Cloud Run service?
To enable WebSockets
To remove the need for revisions
To increase concurrency
To grant least-privilege access
Which flag sets the identity a revision runs as?
--ingress
--invoker
--service-account
--identity-pool

17. How do you use environment variables in Cloud Run?

Set them at deploy time with --set-env-vars KEY=VALUE. Use --update-env-vars to change a few and --remove-env-vars to drop one. Any change creates a new revision.

Cloud Run also supplies reserved variables such as PORT, K_SERVICE, K_REVISION and K_CONFIGURATION, which you cannot override.

Keep passwords and API keys out of plain env vars in config files. Reference them from Secret Manager instead.

Because every change creates a new revision, a typo in a variable can be reverted by sending traffic back to the previous revision. You can also load values from a YAML file with --env-vars-file, which is cleaner than a long command line when a service has many settings.

Take quiz
Which flag changes only some environment variables without replacing all of them?
--clear-env
--update-env-vars
--set-env-vars
--env-file-only
Which variable holds the name of the running Cloud Run service?
CLOUD_RUN_TASK_INDEX
PORT
K_SERVICE
GOOGLE_PROJECT

18. Which languages and runtimes does Cloud Run support?

Cloud Run supports any language because it runs containers. If your app compiles to a Linux binary or runs in a Linux image, it can run there, including Rust, Elixir, Deno and custom runtimes.

For source deploys and Cloud Run functions, Google Cloud buildpacks have first-class support for Go, Node.js, Python, Java, Kotlin, .NET, Ruby and PHP.

The only real requirement is following the container contract: listen on PORT for services or exit on completion for jobs.

Take quiz
Why can Cloud Run run apps written in almost any language?
It runs standard containers
It compiles every app to WebAssembly
It only translates code to Java
It uses a fixed language list in the VM image
What provides automatic builds for Python or Node.js source deploys?
Cloud Armor
Cloud NAT
Cloud CDN
Google Cloud buildpacks

19. Does Cloud Run support WebSockets and gRPC?

Yes. Cloud Run supports WebSockets, HTTP/2 and gRPC, including streaming calls.

A WebSocket connection counts as one long request, so it is limited by the request timeout (up to 60 minutes) and then closed. Clients should be written to reconnect automatically.

Each open connection uses one slot of the instance concurrency, so size concurrency and memory for the number of simultaneous sockets. Session affinity can help keep a client on the same instance across reconnects.

Take quiz
What limits how long a WebSocket connection can stay open on Cloud Run?
The number of revisions
The VPC firewall priority
The Dockerfile EXPOSE value
The request timeout
What should WebSocket clients be built to do?
Use only port 22
Disable TLS
Reconnect after the connection is closed
Never send messages

20. What are Cloud Run worker pools?

Worker pools run containers that continuously process work without receiving HTTP requests. They are meant for pull-based workloads such as Kafka, Pub/Sub pull or queue consumers.

Unlike services, a worker pool has no public URL and is not scaled by request load. You set the instance count manually or with an external autoscaler, and instances are billed while they run.

Worker pools also support Direct VPC egress and ingress, so private systems in your VPC can reach them on a private IP.

Take quiz
Which workload is a good fit for a worker pool?
A one-time schema migration
A Kafka consumer running continuously
A public marketing page
A static image CDN
How are worker pools scaled compared with services?
Not by request load
By DNS TTL
By the number of revisions
By Dockerfile size

21. What is the difference between Cloud Run and Cloud Functions?

Cloud Run deploys containers, while Cloud Functions deploys functions written against a framework with a single entry point. Google has since folded the second generation into Cloud Run as Cloud Run functions, which build a function into a container and run it on Cloud Run.

Aspect Cloud Run service Cloud Run functions
Unit Any container image A single function plus its dependencies
Control Full control over runtime and server Runtime and server set by the framework
Typical use APIs, web apps, custom runtimes Small event handlers and webhooks

Pick Cloud Run when you need a custom runtime or an existing container. Pick functions when a small handler is enough.

Take quiz
What does Cloud Run deploy that a function-only model does not?
Only static HTML
A full container with a custom runtime
Only a single handler file
Only Terraform plans
What are second-generation Cloud Functions now called?
Cloud Run functions
App Engine flex
GKE Autopilot
Cloud Batch

22. When would you choose Cloud Run over GKE?

Choose Cloud Run for stateless HTTP, gRPC or batch workloads where you want no cluster to manage, scale-to-zero and per-use billing.

Choose GKE when you need Kubernetes features Cloud Run does not expose: StatefulSets, DaemonSets, custom operators and CRDs, fine-grained network policies, node-level tuning or complex multi-container scheduling.

Need Better fit
Small team, minimal ops Cloud Run
Spiky or idle-heavy traffic Cloud Run
Stateful sets and custom controllers GKE
Existing Helm and Kubernetes tooling GKE

Many teams start on Cloud Run and move a service to GKE only when a concrete limit appears.

Take quiz
Which requirement points toward GKE rather than Cloud Run?
A webhook receiver
A nightly report job
A stateless REST API with spiky traffic
A custom operator that uses CRDs
What is a key reason to prefer Cloud Run?
Custom CNI plugins
Direct node SSH access
No cluster to operate and scale-to-zero
DaemonSets on every node

23. What is the difference between Cloud Run services and jobs?

A service listens for requests and stays available at a URL, scaling instances with traffic. A job runs its tasks to completion and then stops; it has no URL and does not wait for requests.

Service Job
Listens on PORT Exits when finished
Scales with requests and concurrency Scales by task count and parallelism
Request timeout up to 60 min Task timeout set per task, with retries
Used for APIs and web apps Used for batch and one-off work

If an HTTP request would take longer than a user will wait, trigger a job and return immediately.

Take quiz
Which one exits when its work is finished?
A service
An ingress rule
A traffic tag
A job
Which setting is unique to jobs?
Session affinity
Task count and retries
Custom domain mapping
Request concurrency

24. How does Cloud Run autoscaling work?

Cloud Run adds instances when incoming requests would push existing ones past their limit. It looks mainly at request concurrency and CPU utilization and starts more instances before they are fully saturated.

Scaling is bounded by --min-instances and --max-instances. With a minimum of zero, instances that stay idle are eventually shut down.

While a new instance starts, waiting requests are queued briefly. If capacity does not arrive in time, they fail with an error, so cold start time and concurrency both shape how smoothly a spike is absorbed.

For example, with concurrency 80 and a sudden jump to 400 simultaneous requests, Cloud Run needs roughly five instances and starts the missing ones immediately. Keeping startup short matters because those new instances only help once they pass the startup probe.

Take quiz
What two signals mainly drive Cloud Run autoscaling?
Git commits and image tags
Firewall rules and subnets
Request concurrency and CPU utilization
DNS lookups and disk size
What limits the upper bound of scale-out?
max-instances
The Dockerfile CMD
The revision name
The Artifact Registry region

25. How does request-based billing differ from instance-based billing in Cloud Run?

Under request-based billing (the default), CPU is allocated and billed only while the instance is processing requests, rounded up to the nearest 100 ms, plus a small per-request fee. Outside requests, CPU is throttled.

Under instance-based billing, CPU is always allocated and you pay for the whole lifetime of the instance, with no per-request fee.

Aspect Request-based Instance-based
CPU between requests Throttled Always available
Billed for Request time + request count Full instance lifetime
Best for Bursty or low traffic Steady traffic, background threads, WebSocket-heavy apps

Choose instance-based when the app does work outside requests or traffic is constant enough that the per-request fee adds up.

Take quiz
Which billing model throttles CPU when no request is being processed?
Request-based billing
Spot billing
Committed-use billing only
Instance-based billing
Which workload suits instance-based billing best?
A rarely used internal tool
A webhook called twice a day
A prototype with zero traffic
A service running background threads between requests

26. How can you reduce cold start latency in Cloud Run?

Cold starts come from image pull, container boot and app initialization, so you attack each part:

  1. Set --min-instances to keep warm instances ready.
  2. Enable startup CPU boost (--cpu-boost) so initialization gets extra CPU.
  3. Use a smaller base image and fewer layers so the pull is faster.
  4. Defer heavy work such as large model loads or cache warm-up until after the server is listening, or load lazily.
  5. Reuse clients (database, HTTP) as globals instead of creating them per request.
  6. Try the first generation execution environment if your app does not need full Linux compatibility, since it usually starts faster.

Measure first using startup latency in Cloud Monitoring, because the bottleneck is often application code rather than the platform.

Take quiz
Which flag gives extra CPU while the container is starting?
--max-instances
--vpc-egress
--cpu-boost
--no-traffic
Why reuse database clients as globals?
To switch to HTTP/3
To avoid re-creating connections on every request
To skip the startup probe
To disable autoscaling

27. What is the difference between first and second generation execution environments?

The execution environment is the sandbox your container runs in. You choose it with --execution-environment.

First generation (gen1) Second generation (gen2)
gVisor-based sandbox, emulated Linux syscalls Full Linux kernel compatibility
Typically faster cold starts Slightly slower cold starts
No network file system mounts Supports network file systems such as NFS
Fine for most web apps Better for CPU-heavy work and syscall-heavy software

If an app fails with a missing syscall or needs NFS or Cloud Storage volume mounts, use gen2. If you only serve HTTP and care about startup time, gen1 may be enough.

Take quiz
Which environment offers full Linux compatibility?
Neither of them
Only the jobs runtime
Second generation
First generation
Which generation is usually quicker at cold starting?
First generation
Whichever has more instances
Second generation
Both are identical

28. How does traffic splitting work in Cloud Run?

A service can send traffic to several revisions at once. You assign percentages that add up to 100, and Cloud Run distributes requests accordingly.

gcloud run services update-traffic orders-api \
  --to-revisions orders-api-00012-xyz=90,orders-api-00013-abc=10

Use --to-latest to send all traffic to the newest revision. Revisions can also get tags, which create a dedicated URL for testing a revision directly without giving it any percentage of live traffic.

Splitting is per request, not per user, unless you enable session affinity so a client tends to stay on the same revision.

A typical use is a 90/10 split between a stable and a new revision while you compare error rates. Percentages apply to the whole service, so a revision at 10% still gets about one request in ten even if it has a tag URL as well.

Take quiz
What must the percentages of a traffic split add up to?
50
100
1000
10
What does a revision tag give you?
A new project
A larger memory limit
An extra service account
A dedicated test URL for that revision

29. How do you perform a canary deployment in Cloud Run?

Deploy the new revision without sending it traffic, test it through a tag URL, then shift traffic in steps.

  1. Deploy with --no-traffic --tag canary.
  2. Test the tagged URL with real calls and smoke tests.
  3. Send a small share, for example 5%, using update-traffic --to-revisions.
  4. Watch error rate and latency in Cloud Monitoring.
  5. Increase to 25%, 50% and then 100% if the metrics stay healthy.
gcloud run deploy api --image IMAGE --no-traffic --tag canary

If metrics worsen, set the previous revision back to 100% and the canary disappears from live traffic immediately.

Take quiz
Which flag deploys a revision without routing any live traffic to it?
--no-traffic
--min-instances
--cpu-boost
--allow-unauthenticated
What should you check before raising the canary percentage?
The number of Artifact Registry repos
Error rate and latency of the canary revision
The size of the Git history
The DNS TTL of the project

30. How do you roll back a bad release in Cloud Run?

Send traffic back to the last good revision. Because revisions are immutable, this takes effect within seconds and needs no rebuild.

gcloud run services update-traffic orders-api \
  --to-revisions orders-api-00012-xyz=100

Find the revision name with gcloud run revisions list --service orders-api. If the service was pinned to --to-latest, a rollback also needs traffic pinned to a named revision, otherwise the next deploy will take traffic again.

Check the result by calling the service and confirming the old behavior is back. Afterwards, fix the bug, deploy a new revision with --no-traffic and promote it deliberately, so the same problem does not return through an automatic deploy to latest.

Take quiz
What is the quickest way to roll back a Cloud Run service?
Rebuild the VPC
Rotate the service account key
Delete the project
Route 100% of traffic to the previous revision
Why is a Cloud Run rollback fast?
Cloud Run rebuilds the image from Git
It resets IAM policies
Revisions are immutable and already exist
It restarts every region

31. How do you secure service-to-service calls in Cloud Run?

Keep the target service private and let callers authenticate with Google-signed ID tokens.

  1. Remove public access so the target requires authentication.
  2. Grant the caller's service account roles/run.invoker on the target service.
  3. In the caller, fetch an ID token from the metadata server with the target URL as the audience.
  4. Send it as Authorization: Bearer TOKEN.
import google.auth.transport.requests, google.oauth2.id_token, requests
target = "https://billing-abc123-uc.a.run.app"
token = google.oauth2.id_token.fetch_id_token(google.auth.transport.requests.Request(), target)
r = requests.get(target + "/invoices", headers={"Authorization": f"Bearer {token}"})

Cloud Run checks the token signature, audience and IAM permission before the request reaches your code.

Take quiz
What must the audience of the ID token be set to?
The region name
The URL of the target service
The caller's project number
The caller's container image
Which role lets the caller's service account invoke the target?
roles/storage.admin
roles/run.viewer
roles/logging.writer
roles/run.invoker

32. How do you manage secrets in Cloud Run?

Store secrets in Secret Manager and reference them from the service rather than baking them into the image or plain env vars.

Method Flag Behavior
Environment variable --set-secrets DB_PASS=db-pass:3 Value resolved when the instance starts
Mounted file --set-secrets /secrets/db-pass=db-pass:latest Read from the mounted path at access time

The service account needs roles/secretmanager.secretAccessor. Pin a numbered version for repeatable deployments. Using latest with a file mount lets you rotate a secret without a redeploy, while an env var secret only changes on new instances.

Never print secret values in logs and avoid putting them in the container image or build arguments, since both are easy to leak. Rotating a secret means adding a new version in Secret Manager and then deploying a revision that points to it, unless the service reads the latest version from a mounted file.

Take quiz
Which role must the service account hold to read a secret?
roles/secretmanager.secretAccessor
roles/pubsub.viewer
roles/run.invoker
roles/compute.admin
Why pin a numbered secret version?
To bypass IAM
To make the image smaller
For repeatable, predictable deployments
To increase concurrency

33. How does Cloud Run connect to resources inside a VPC?

Cloud Run itself runs outside your VPC, so you add a path in. There are two options: Direct VPC egress and a Serverless VPC Access connector.

Both let the service reach private IPs such as a Memorystore Redis instance or an internal API. The --vpc-egress flag controls whether only private ranges or all outbound traffic goes through the VPC.

Use private-ranges-only to keep public API calls on the default path, or all-traffic when egress must pass through Cloud NAT with a fixed IP or through firewall rules.

flowchart LR
  A["Cloud Run instance"] -->|Direct VPC egress or connector| B["VPC subnet"]
  B --> C["Memorystore / Cloud SQL private IP"]
  B --> D["Cloud NAT with static IP"]
  D --> E["Third-party API allowlist"]
Take quiz
What does --vpc-egress=all-traffic do?
Disables HTTPS
Doubles the instance count
Sends all outbound traffic through the VPC
Opens inbound port 22
Why route all egress through the VPC with Cloud NAT?
To present a fixed outbound IP
To skip the container contract
To avoid IAM checks
To enable scale-to-zero

34. What is the difference between Direct VPC egress and a Serverless VPC Access connector?

Both give Cloud Run outbound access to a VPC. The difference is how.

Direct VPC egress Serverless VPC Access connector
Instances get IPs from your subnet Traffic is proxied through connector VMs
No separate resource to manage or pay for Connector instances are billed and must be sized
Lower latency, scales with the service Throughput limited by connector size
Needs enough free IPs in the subnet Needs a dedicated /28 range

Direct VPC egress is the simpler default for new services. A connector still makes sense for older setups or where its behavior is already relied on.

Take quiz
Where do instances get IP addresses with Direct VPC egress?
From the connector VMs
From your own subnet
From the Artifact Registry
From a global anycast pool
What extra cost does a connector add?
A per-tag fee
A per-image fee
A per-revision fee
Billed connector instances

35. How do you connect a Cloud Run service to Cloud SQL?

There are two common routes.

  1. Built-in connector over a unix socket: deploy with --add-cloudsql-instances PROJECT:REGION:INSTANCE. Your app connects to /cloudsql/PROJECT:REGION:INSTANCE.
  2. Private IP: give the service VPC access and connect to the instance's private address like any other host.

The service account needs roles/cloudsql.client. Keep the database password in Secret Manager.

Remember that each instance opens its own pool. Cap --max-instances and pool size so total connections stay under the database limit.

For local development, the Cloud SQL Auth Proxy gives the same socket-style connection, so the connection string in code can stay almost identical between your laptop and Cloud Run. Use IAM database authentication where your engine supports it to avoid passwords entirely.

Take quiz
Which role does the service account need to use the built-in Cloud SQL connection?
roles/run.developer
roles/cloudsql.client
roles/storage.objectViewer
roles/owner
Why limit max instances for a Cloud SQL backed service?
Unix sockets stop working
Revisions share one pool
Each instance opens its own connection pool
Cloud SQL disables scaling

36. How do ingress settings control access to Cloud Run?

The --ingress setting decides which network paths can reach the service, before IAM is even checked.

Value Who can reach it
all Any client, including the public internet
internal Only traffic from the same project or VPC Service Controls perimeter, plus some Google services
internal-and-cloud-load-balancing Internal traffic plus an external Application Load Balancer

Use internal-and-cloud-load-balancing when you want Cloud Armor or a custom domain in front and no direct run.app access. Ingress and IAM are separate layers, so a public service still needs allUsers as invoker.

Use internal for private backends that only other services in your project call, such as an internal pricing API. Changing ingress creates a new revision, so test the new value on a tagged revision before moving all traffic to it.

Take quiz
Which ingress value allows only a load balancer and internal traffic?
internal-and-cloud-load-balancing
none
all
public-only
Is ingress a replacement for IAM invoker checks?
Yes, but only in jobs
Yes, IAM is ignored
Only for gRPC
No, they are separate layers

37. When should you put a load balancer in front of Cloud Run?

A global external Application Load Balancer with a serverless NEG adds features Cloud Run does not offer by itself.

  • Cloud Armor for WAF rules and rate limiting.
  • Cloud CDN to cache responses.
  • A custom domain with managed certificates and a single anycast IP.
  • Multi-region routing across Cloud Run services in different regions.
  • Identity-Aware Proxy for user sign-in.

Pair it with --ingress internal-and-cloud-load-balancing so users cannot skip the load balancer through the run.app URL. For a simple internal tool, the default URL is enough.

One more reason is a stable set of anycast IP addresses, which partners sometimes need for firewall allowlists. Keep in mind the load balancer adds its own cost and one more hop to debug, so only add it when one of these features is required.

Take quiz
Which load balancer feature protects Cloud Run from web attacks?
Cloud Tasks
Cloud Armor
Cloud Scheduler
Cloud Build
Which backend type connects a load balancer to Cloud Run?
Managed instance group
Unmanaged instance group
Internet NEG to a VM
Serverless NEG

38. What happens when Cloud Run reaches max instances?

Once every allowed instance is at its concurrency limit, new requests cannot start more capacity. Cloud Run keeps them in a short queue, and if no slot opens in time they are rejected, usually with a 429.

Callers see errors even though the service is healthy, so it looks like an outage under load.

  1. Raise --max-instances or the project quota if downstream systems can cope.
  2. Raise --concurrency if the app can handle more parallel requests.
  3. Speed up requests so slots free faster.
  4. Buffer bursts with Cloud Tasks or Pub/Sub instead of direct calls.
Take quiz
What error is typical when no instance can accept more requests?
429
201
410
301
Which change lets each instance handle more simultaneous work?
Changing the region
Lowering the timeout
Raising concurrency, if the app is safe for it
Adding a tag

39. Why do Cloud Run requests return 504 errors?

A 504 means the container did not send a response within the request timeout. The clock includes container startup when the request triggered a cold start.

Common causes:

  • Slow downstream calls with no client timeout, such as a database or third-party API.
  • Heavy work done inline, like exports or image processing.
  • A cold start that eats most of the timeout.
  • Timeout left at the 300 second default while the work needs longer.

Fix it by adding timeouts and retries to downstream calls, moving long tasks to jobs or Cloud Tasks, and raising --timeout only when the work truly needs it.

Take quiz
What does a 504 on Cloud Run usually indicate?
The image tag is missing
IAM denied the caller
The response did not arrive within the request timeout
The domain certificate expired
Which fix removes long work from the request path?
Lower concurrency to 0
Hand it to a Cloud Run job or Cloud Tasks
Delete old revisions
Disable logging

40. How do you troubleshoot a Cloud Run container that fails to start?

The typical error says the container failed to start and listen on the expected port. Work through these checks:

  1. Open the revision's logs in Cloud Logging and read the last lines before the crash.
  2. Confirm the app listens on 0.0.0.0:$PORT, not 127.0.0.1 or a fixed port.
  3. Run the image locally with docker run -e PORT=8080 -p 8080:8080 IMAGE.
  4. Check for missing environment variables, secrets or permissions that crash the app at startup.
  5. Verify the image is built for 64-bit Linux and the entrypoint is correct.
  6. If startup is slow, extend the startup probe or enable CPU boost.

Most failures are a wrong bind address, a missing secret or a crash in startup code.

Take quiz
Which address binding commonly causes the failed-to-start error?
Logging to stdout
Listening on 0.0.0.0
Reading PORT
Listening on 127.0.0.1
Which local test helps reproduce a startup failure?
docker run with the PORT variable set
git rebase
gcloud auth revoke
terraform destroy

41. How do you run background or event-driven workloads on Cloud Run?

A service only runs when requests arrive, so events are delivered to it over HTTP.

Trigger How it reaches Cloud Run
Pub/Sub Push subscription calls the service URL with an OIDC token
Cloud Storage and other Google events Eventarc forwards events as HTTP requests
Scheduled work Cloud Scheduler calls a service or starts a job
Deferred tasks with retries Cloud Tasks queue sends HTTP requests

Return a 2xx status only after the work is done, or the sender will retry. Make handlers idempotent since delivery is at least once. For continuous pull-based consumers, use a worker pool instead.

For example, an upload to a bucket can trigger Eventarc, which calls a Cloud Run service to generate thumbnails. If the handler returns a 5xx, the event is redelivered, so use a unique event or object ID to ignore duplicates and send repeated failures to a dead-letter topic.

Take quiz
Which service delivers Cloud Storage events to Cloud Run over HTTP?
Cloud NAT
Eventarc
Cloud DNS
Cloud CDN
Why should event handlers be idempotent?
Because revisions share memory
Because Pub/Sub sends only one copy
Because Cloud Run forbids retries
Delivery can happen more than once

42. How does Cloud Run handle container shutdown and SIGTERM?

When Cloud Run stops an instance, for example on scale-in or a new deploy, it sends SIGTERM to the container. You then have about 10 seconds before it sends SIGKILL.

Use that window to stop accepting new work, finish in-flight requests, flush buffers and close database connections.

process.on('SIGTERM', () => {
  server.close(() => { db.end().then(() => process.exit(0)); });
});

Anything that needs longer, such as a long job step, should be checkpointed so another instance can resume it.

Test this locally by running the container and sending docker stop, which also delivers SIGTERM. A handler that ignores the signal gets killed mid-request, which clients see as connection resets during deploys and scale-in. Log a short message when the handler starts so you can confirm it ran.

Take quiz
Which signal does Cloud Run send first when stopping an instance?
SIGSTOP
SIGHUP
SIGTERM
SIGUSR1
Roughly how long do you get before SIGKILL?
10 seconds
1 hour
10 minutes
No time at all

43. How does file storage work in Cloud Run?

The container filesystem is writable but in-memory. Files you write count against the instance memory limit and disappear when the instance stops, and they are not shared between instances.

For data that must survive or be shared, use an external store:

  • Cloud Storage, through the client library or a mounted bucket volume.
  • NFS shares such as Filestore, mounted as a volume.
  • A database such as Cloud SQL or Firestore for structured data.

Treat local disk as scratch space only, and delete temporary files after use so they do not exhaust memory.

A bucket mounted as a volume works through Cloud Storage FUSE, so it behaves like a folder but is not a full POSIX file system. It suits reading shared assets or writing finished output, and it is a poor fit for databases or heavy random writes.

Take quiz
What happens to files written to the container filesystem when the instance stops?
They are lost
They stay on a shared disk
They are copied to the next revision
They sync to Cloud Storage automatically
Why can writing big temp files cause out-of-memory errors?
It uses the IAM cache
It uses Artifact Registry space
The writable filesystem uses instance memory
It uses the VPC quota

44. What are startup and liveness probes in Cloud Run?

Probes let Cloud Run check container health beyond just starting the process.

A startup probe decides when the instance is ready to receive traffic. The default is a TCP check on the container port. You can switch to an HTTP or gRPC check against a path such as /healthz, with delay, period and failure threshold settings.

A liveness probe runs after startup. If it keeps failing, Cloud Run restarts the container.

Use a startup probe for apps with slow initialization so no request arrives before caches or models are loaded, and a liveness probe to recover from deadlocks.

Keep the health endpoint cheap. It should confirm the process is alive, and for readiness it can check only local state. If it calls the database on every probe, a short database outage can make Cloud Run restart every healthy instance and make the incident worse.

Take quiz
Which probe decides when an instance can start receiving traffic?
DNS probe
Billing probe
Liveness probe
Startup probe
What does Cloud Run do when a liveness probe keeps failing?
Deletes the revision
Restarts the container
Raises the concurrency
Switches the region

45. How do you tune concurrency and CPU for a Cloud Run service?

Start with the defaults, then load test and adjust using metrics.

  1. Run a load test, for example with hey or k6, at realistic traffic.
  2. Watch CPU and memory utilization and request latency in Cloud Monitoring.
  3. If CPU stays low and latency is fine, raise --concurrency so fewer instances serve the same load.
  4. If latency climbs with load, lower concurrency or add CPU.
  5. Match runtime settings: for example set worker threads in Gunicorn or the thread pool in Java to fit the concurrency value.

A single vCPU with high concurrency suits I/O-bound apps. CPU-bound work does better with more vCPUs and lower concurrency. Memory must fit all in-flight requests at once.

Take quiz
What is a good sign you can raise concurrency?
Frequent 404 responses
Low CPU use with acceptable latency
Missing environment variables
A failing image pull
Which workload favors lower concurrency and more vCPUs?
Simple redirects
Mostly idle I/O waiting
CPU-bound request handling
Static file proxying

46. How can you optimize Cloud Run costs?

Costs come from CPU, memory and request counts, so reduce each where it is safe.

  • Right-size CPU and memory using real utilization instead of guesses.
  • Raise concurrency so fewer instances handle the same traffic.
  • Keep request-based billing for bursty services and use min instances only where latency demands it.
  • Set max instances as a guardrail against runaway spend.
  • Cache responses with Cloud CDN to cut requests.
  • Move batch work to jobs that run only when needed.
  • Review committed use discounts for steady baseline load.

Check billing reports by service regularly, since a forgotten min-instances setting is a common small leak.

Take quiz
Which change usually reduces instance count for the same traffic?
Increasing concurrency safely
Lowering max instances to 0
Using bigger images
Adding more revisions
Which setting acts as a guardrail against runaway spend?
cpu-boost
execution-environment
allow-unauthenticated
max-instances

47. How do you monitor a Cloud Run service?

Cloud Run integrates with Google Cloud's observability tools without extra agents.

Tool What it gives you
Cloud Logging stdout and stderr plus automatic request logs; JSON logs with a severity field are parsed
Cloud Monitoring Metrics like request count, request latencies, instance count, CPU and memory utilization
Cloud Trace Latency breakdown across services
Error Reporting Grouped exceptions from logs

Set alerts on 5xx rate, p95 latency and instance count nearing the max. Write structured logs with a trace ID so one request can be followed across services.

A useful starting dashboard has request count, 5xx percentage, p50 and p95 latency, instance count and memory utilization on one page. Add a log-based metric for known error messages so recurring application failures show up as a chart instead of a search.

Take quiz
Which format makes Cloud Run logs easier to filter by severity?
Screenshots
Binary blobs
Structured JSON with a severity field
Random free text only
Which alert helps spot a service nearing its scaling cap?
Docker image size
Number of tags
Git commit count
Instance count close to max-instances

48. Explain the lifecycle of a request handled by Cloud Run?

A request enters Google's front end, is authenticated and routed, and either lands on a ready instance or waits for a new one.

sequenceDiagram
  participant C as Client
  participant G as Google Front End
  participant R as Cloud Run Router
  participant I as Container Instance
  C->>G: HTTPS request
  G->>R: Check ingress and IAM
  alt Instance has free concurrency
    R->>I: Forward HTTP request
  else No capacity
    R->>I: Start new instance, queue request
    I-->>R: Startup probe passes
    R->>I: Forward queued request
  end
  I-->>C: Response before timeout
  1. TLS terminates at Google's edge and the host is matched to the service.
  2. Ingress and IAM checks run.
  3. The router picks an instance with spare concurrency, or starts one and queues the request briefly.
  4. The container handles the request and replies within the timeout.

Delays show up as cold start latency, a 429 when capacity is capped or a 504 when the response is late.

Take quiz
Where does TLS terminate for a Cloud Run service?
At Google's front end
In the Dockerfile
Inside your container
On Cloud Build
What happens when no instance has free concurrency?
DNS is changed
A new instance starts and the request waits briefly
The request is silently dropped
The revision is deleted

49. Explain the deployment flow from source code to a live Cloud Run revision?

A source deploy chains several managed steps.

flowchart TD
  A["gcloud run deploy --source"] --> B["Upload source to Cloud Build"]
  B --> C{Dockerfile present?}
  C -->|Yes| D["Docker build"]
  C -->|No| E["Buildpacks detect language"]
  D --> F["Push image to Artifact Registry"]
  E --> F
  F --> G["Create new revision"]
  G --> H{Startup probe passes?}
  H -->|Yes| I["Route traffic to revision"]
  H -->|No| J["Revision fails, old one keeps serving"]

If the new revision fails its startup check, the previous revision keeps serving traffic, so a bad image does not cause downtime. With --no-traffic, the final routing step is skipped until you shift traffic yourself.

Take quiz
What happens if a new revision fails its startup check?
The service is deleted
All traffic is dropped
The previous revision keeps serving traffic
Traffic goes to Cloud SQL
Where does the built image get stored in a source deploy?
Cloud Scheduler
Artifact Registry
Secret Manager
Cloud DNS

50. How do you implement multi-region high availability on Cloud Run?

A single Cloud Run service lives in one region, so high availability across regions means deploying the same service in several regions and routing between them.

  1. Deploy identical revisions to two or more regions, for example us-central1 and europe-west1.
  2. Create a serverless NEG per region and attach them to one backend service on a global external Application Load Balancer.
  3. Let the load balancer send users to the closest healthy region and fail over when one stops responding.
  4. Use ingress internal-and-cloud-load-balancing so traffic always goes through the load balancer.

The data layer must match the design. Use multi-region or replicated stores such as Spanner, Firestore or multi-region buckets, or the stateless front end will fail over while its database does not.

Test failover regularly by draining one region and watching latency and error rates in the other.

Take quiz
What connects a load balancer backend to a regional Cloud Run service?
A Cloud NAT gateway
A DNS zone transfer
A VPN tunnel
A serverless NEG
Why must the data layer also be multi-region?
Otherwise failover moves compute but not the database
IAM requires it
Revisions replicate tables
Cloud Run stores data in the load balancer
«
»

Comments & Discussions