1.2 Cloud Run Execution and Platform Selection
Key Takeaways
Cloud Run services receive requests on the configured PORT and use external durable storage.
Concurrency is an explicit workload setting; new-service defaults differ between console and CLI/Terraform.
Instance-based CPU helps between requests but does not guarantee durable post-response execution.
Compute Platform Selection: Cloud Run, GKE, and Compute Engine
Designing cloud-native applications on Google Cloud begins with selecting the compute platform that matches your workload's operational profile, scaling requirements, hardware dependencies, and execution model. The Google Cloud Professional Cloud Developer exam tests your ability to evaluate trade-offs between fully managed serverless containers (Cloud Run), enterprise container orchestration (Google Kubernetes Engine / GKE), and Infrastructure as a Service (Compute Engine).
Cloud Run: Fully Managed Serverless Containers
Cloud Run executes containers without requiring cluster management, VM provisioning, or node OS patching. Its container contract and Knative-style configuration support portable application packaging, but networking, identity, triggers, and managed-service integrations still require migration work.
Core Capabilities and Runtime Semantics
- Scale-to-Zero and Instant Elasticity: When no traffic arrives, Cloud Run scales active container instances to zero, avoiding instance compute charges when scaled to zero; other services, storage, and networking can still incur charges. When an HTTP request, gRPC call, or Eventarc event arrives, Cloud Run provisions container instances in milliseconds to seconds.
- Container Port Contract: The containerized application must listen for incoming HTTP/1.1, HTTP/2, or gRPC requests on the port specified by the
PORTenvironment variable (default8080), binding to0.0.0.0. - Stateless Execution: Container file systems are ephemeral and memory-backed (written to RAM). Persistent data must be committed to external storage systems such as Cloud Storage, Cloud SQL, Firestore, or Cloud Spanner.
- Request Timeout: Individual request execution is bounded by a configurable timeout (default 5 minutes, configurable up to 60 minutes for HTTP services, and up to 168 hours per non-GPU Cloud Run job task attempt; GPU tasks have a 1-hour maximum).
Concurrency and Scaling Triggers
Unlike traditional Functions-as-a-Service (FaaS) platforms where each instance handles only one request at a time, Cloud Run supports multi-concurrency:
- Container Concurrency (
--concurrency): Defines the maximum number of simultaneous requests a single container instance can receive (maximum1000; console-created services default to80, while new CLI/Terraform services default to80times vCPU count). - Multi-threaded vs. Single-threaded Runtimes: For multi-threaded runtimes (Go, Java, .NET, Rust), high concurrency (e.g.,
80to250) optimizes resource utilization and lowers cost. For CPU-heavy single-threaded handlers, lower concurrency can reduce contention. I/O-bound Node.js handlers can efficiently overlap requests. Load-test the actual framework and worker count instead of assigning concurrency solely from language choice.
## Deploying a high-concurrency microservice to Cloud Run
gcloud run deploy order-service \
--image=us-central1-docker.pkg.dev/my-project/apps/order-service:v1.2 \
--concurrency=80 \
--min-instances=2 \
--max-instances=100 \
--cpu=2 \
--memory=2Gi \
--no-cpu-throttling \
--region=us-central1
CPU Allocation Models
Cloud Run offers two distinct CPU allocation models that dictate pricing and execution guarantees:
| Feature | Request-Based CPU Allocation (cpu-throttling) | Always-Allocated CPU (--no-cpu-throttling) |
|---|---|---|
| CPU Availability | CPU is only allocated during request processing and lifecycle events | CPU is continuously allocated for the entire container instance lifetime |
| Background Threads | Throttled to near-zero when no active requests are pending | Full CPU cycles available for background processing between requests |
| Billing Model | Billed per vCPU-second and GiB-second during active request handling | Billed for the entire time the instance is running (warm or active) |
| Cost Profile | Lowest cost for intermittent, bursty, or spiky request traffic | Higher baseline cost; comparable to persistent VM pricing |
| Use Cases | Synchronous REST/gRPC APIs, webhooks, short-lived tasks | Pub/Sub subscriber pull loops, background batch caching, metrics flushing |
Exam Trap: If a developer launches a background goroutine or thread to flush logs, send telemetry, or execute asynchronous cleanup after returning the HTTP response, request-based CPU allocation will throttle the CPU almost immediately. The thread will freeze until a subsequent request wakes the instance, leading to dropped telemetry or delayed processing. To execute background threads safely between requests, specify
--no-cpu-throttling.
Cold Starts and Mitigation Strategies
A cold start occurs when Cloud Run provisions a new container instance from scratch to handle incoming traffic. Cold start latency comprises container image pull time, container start, and runtime/application initialization.
- Minimum Instances (
--min-instances): Keeps a predetermined number of container instances initialized, warm, and ready to serve traffic immediately, reducing cold starts for baseline traffic; replacements and traffic growth can still require new instances. - Startup CPU Boost (
--cpu-boost): Temporarily allocates extra vCPUs during container initialization (startup probe and app boot) to reduce initialization latency; the improvement depends on the workload before scaling down to configured steady-state CPU limits. - Image Size Optimization: Use minimal base images (Distroless, Alpine) stored in Artifact Registry near the workload to reduce transfer overhead; measure application initialization rather than assuming image size determines startup latency.
Official references checked October 18, 2026: Google Cloud 1, Google Cloud 2.
A developer deploys a Go microservice to Cloud Run that processes image uploads. After returning an HTTP 200 OK response to the client, the service launches a background goroutine to generate thumbnail variations and publish telemetry to Cloud Logging. Users report that thumbnails are generated inconsistently or only finish processing when new upload requests arrive hours later. Which configuration addresses CPU throttling while the instance remains alive? Required thumbnail completion also needs durable dispatch and idempotency.
Configure always-allocated CPU by deploying the Cloud Run service with the --no-cpu-throttling flag
Increase the container instance memory allocation to 4 GiB using the --memory=4Gi flag
Increase the Cloud Run request timeout to 3600 seconds using the --timeout=3600 flag
Increase the container concurrency limit to 250 using the --concurrency=250 flag
An e-commerce company launches a flash sale. Their Cloud Run microservice handles thousands of incoming checkout requests by rapidly scaling out container instances. Within minutes, the backend Cloud SQL PostgreSQL instance crashes due to connection pool exhaustion. How should the developer protect the database while maintaining high availability on Cloud Run?
Switch the workload to Compute Engine Managed Instance Groups with autoscaling disabled
Set the --max-instances flag on the Cloud Run service and implement a connection pooler like PgBouncer
Configure container concurrency to 1 to force single-threaded execution per container
Enable Cloud Run Startup CPU Boost to accelerate container cold start initialization
Sections you finish are checked off in the contents.