Guide
Diagnosing Intermittent 5xx Errors and Latency Spikes in Google Cloud Run
A step‑by‑step diagnostic guide for intermittent 5xx errors and latency spikes in Google Cloud Run, with checks, fixes, and escalation criteria.
Published by Tasadduq Burney
05 Jul 2026, 06:16 UTC
5 min57.9K views0

Recognizable condition
A Cloud Run service behaves normally under low traffic but, during bursts or after idle periods, you observe one or more of the following:
- Intermittent HTTP 429 (Too Many Requests) or 503 (Service Unavailable) responses.
- Elevated p95/p99 latency (often >2 seconds) on the first request after a period of no traffic.
- HTTP 504 (Gateway Timeout) errors when the request exceeds the configured timeout.
- Logs contain messages such as "no available instance" or "container startup failed".
Cause / diagnostic table
| Symptom | Likely cause | First check |
|---|---|---|
| 429/503 at peak load | Maximum instance limit reached | Compare the "instance count" metric against the service’s configured maximum. |
| Latency spike on first request after idle | Cold start (scale‑from‑zero) | Review the "min instances" setting, image size, and observed container startup latency. |
| 504 timeout | Request timeout exceeded | Check the service’s timeout setting and downstream latency. |
| High CPU usage after response returns | CPU throttled outside request handling | Verify CPU allocation mode (CPU always allocated vs. CPU only during request). |
Ordered checks
- Correlate errors with instance‑count and request‑count metrics
- In Cloud Monitoring, view the "instance count" and "request count" metrics for the service over the time window of the incident.
- If request count rises while instance count stays flat at the configured maximum, the service is saturating its scale‑up limit.
- If instance count drops to zero before a burst of requests, the issue is scale‑from‑zero (cold start).
- Inspect revision settings
- Run (replace placeholders):
gcloud run services describe SERVICE \ --region REGION \ --format="value(spec.template.spec.containerConcurrency,spec.template.spec.maxInstanceCount,spec.template.spec.minInstanceCount,spec.template.spec.timeout,spec.template.spec.cpu)"Required permission:
run.services.geton the service. - Note the values for concurrency, max/min instances, timeout (seconds), and CPU allocation.
- Run (replace placeholders):
- Check container startup behavior
- Ensure the container listens on the port provided by the
$PORTenvironment variable. - Verify that a startup probe (if defined) succeeds within the probe period; look for logs like "startup probe failed".
- Measure image pull time and framework warm‑up by examining the "container startup latency" metric in Cloud Monitoring.
- Ensure the container listens on the port provided by the
- Test downstream dependencies and egress paths
- If the service calls external APIs or databases, monitor those services for latency or errors during the same window.
- Use VPC Flow Logs or Cloud NAT metrics to confirm outbound traffic is not being throttled.
Fixes tied to findings
- Cold starts
- Increase
minInstanceCountto keep at least N instances warm. - Reduce container image size (multi‑stage builds, remove unnecessary layers).
- Lazy‑initialize heavy clients (e.g., database drivers) inside request handlers rather than at global scope.
- Enable CPU boost during startup (
--cpu-boost) if using Cloud Run (fully managed) Gen 2.
- Increase
- Maximum instance saturation
- Raise
maxInstanceCount(subject to regional quota). - If raising the cap is not feasible, introduce client‑side backpressure, a queue (Pub/Sub + Cloud Run worker), or rate‑limit incoming traffic.
- Raise
- CPU throttling outside requests
- Switch to always‑allocated CPU: set
--cpu=always(orcpu: alwaysin YAML). - Note: this changes billing to charge for CPU time even when no requests are being processed.
- Switch to always‑allocated CPU: set
- 504 timeout
- Increase the timeout (
--timeout=...) if the workload legitimately needs more time. - Alternatively, move long‑running work to an asynchronous job (Cloud Run Jobs) and return a 202 Accepted immediately.
- Increase the timeout (
- Startup probe failure
- Ensure the container binds to
0.0.0.0:$PORTand begins listening before the probe period expires. - Adjust the probe’s initial delay or period if the framework needs more warm‑up time.
- Ensure the container binds to
Escalation criteria
Consider escalating when:
- Errors persist after applying the above fixes and rolling back to a previously known‑good revision.
- Quota or limit increases are required (regional CPU, maximum instances) and you need to request a quota increase via Cloud Console.
- The same symptoms appear across unrelated services or regions, suggesting a platform‑wide incident.
- Your service‑level objective (SLO) continues to be breached despite configuration changes and with no identifiable dependency cause.
Practical decision framing
Concurrency, min instances, and CPU allocation involve trade‑offs:
- Concurrency – Higher values increase throughput per instance but reduce per‑request CPU/memory headroom, which can raise latency if the request is CPU‑bound.
- Min instances – Reduces cold‑start latency at the cost of paying for idle instances.
- Always‑allocated CPU – Guarantees CPU for background threads or timers but incurs cost even when the service receives no traffic.
Choose values by measuring:
- Latency percentiles (p50, p95, p99) under realistic load.
- Billable instance time (sum of instance‑seconds) in Cloud Billing reports.
- Adjust iteratively, using traffic splitting (
--traffic) to route a small percentage of traffic to a revised configuration and compare metrics before promoting.
Verification steps
- Deploy a canary revision with the proposed change and route 5‑10 % of traffic to it.
- Monitor the following metrics in Cloud Monitoring for both the canary and the baseline:
- Request latency distribution.
- Instance count.
- Container startup latency.
- Error rates (4xx/5xx).
- Run a load test that ramps from zero to peak traffic (e.g., using Locust or k6) and repeat after each configuration change to confirm the fix.
- Inspect revision logs for "no available instance" or "container startup failed" messages; ensure they disappear after the fix.
- Verify downstream dependency latency separately (e.g., Cloud SQL query latency) to rule out external causes.
Limitations and practical checks
- The exact default values for concurrency, timeout, min instances, and CPU allocation have changed across Cloud Run generations; always verify the current defaults in the console or documentation before assuming a value.
- Quotas, maximum instance limits, and timeout ceilings are region‑ and account‑specific; treat any numeric examples as illustrative only.
- Cloud Run services, jobs, and functions share branding but have distinct configuration surfaces; do not copy settings blindly between them.
- Increasing min instances or enabling always‑allocated CPU raises cost even with zero traffic; estimate the monthly cost using the Cloud Pricing Calculator before applying as a fix.
This guide reflects well‑known behavior of Google Cloud Run as of the knowledge cutoff. Always validate changes in a staging environment and monitor production metrics.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.