---
title: "The Cloud SQL Auth Proxy sidecar starts after the app on Cloud Run | Proofline"
description: "When a Cloud Run service runs the Cloud SQL Auth Proxy as a sidecar, the application can try the database before the proxy listens."
url: https://proofline.sh/learn/cloud-run-cloud-sql-auth-proxy-sidecar-start-order/
---

[Learning center](/learn/)

# The Cloud SQL Auth Proxy sidecar starts after the app on Cloud Run

When a Cloud Run service runs the Cloud SQL Auth Proxy as a sidecar, the application can try the database before the proxy listens. Make the app depend on the proxy container, and give the proxy a startup probe, or Cloud Run starts the containers in order without waiting. If you need none of the proxy's own options, the built-in Cloud SQL connection avoids the question.

Deployment failures The Proofline team November 23, 2026 7 min read

## How it shows up

A revision that adds the proxy as a second container fails on some instances and not others. The application's first log line after start says the connection to `127.0.0.1:5432`, or to the socket the proxy should create, was refused or not found. A second later the proxy's log says it is listening. If the application exits when its first connection fails, the instance fails its startup probe and the revision may never [become ready](/learn/cloud-run-revision-not-ready/); if it retries, the instance serves after a slow first request.

This is stage 1 in [the four stages](/learn/cloud-run-cloud-sql-connection-errors/#stage): the path does not exist yet. The same message from a revision that has no sidecar has a different cause, which the hub's stage table traces.

## Why the containers can start in any order

All containers in a Cloud Run instance share one network namespace, so the application reaches the sidecar on `localhost`. Containers that have no dependencies are started first and concurrently. Container dependencies change that: you list, for each container, the containers that must start before it, in the revision annotation `run.googleapis.com/container-dependencies` or with `gcloud run deploy --depends-on`. [Deploy sidecars](https://cloud.google.com/run/docs/deploying#sidecars) · [Container start order](https://cloud.google.com/run/docs/configuring/services/containers#container-ordering)

A dependency on its own does not wait for the proxy to be ready. Cloud Run's documentation says you must use startup probes for the feature to work: with a probe, Cloud Run checks that a dependency passes before it starts the next container; without one, the containers start in the listed order even if the dependency fails to start. The ingress container has a default startup probe, and sidecars do not. [Container start order](https://cloud.google.com/run/docs/configuring/services/containers#container-ordering)

With request-based billing, Cloud Run's default, a sidecar gets CPU only while the instance processes a request or the ingress container starts. Cloud Run recommends a startup probe on the sidecar so that it is not throttled during startup. [Sidecars and CPU](https://cloud.google.com/run/docs/deploying#sidecars)

## Check 1: read what the revision declares

```
gcloud run revisions describe REVISION \
  --project shop-prod --region europe-west1 \
  --format='yaml(metadata.annotations, spec.containers)'
```

Look for three things: the `run.googleapis.com/container-dependencies` annotation, a `startupProbe` on the proxy container, and the port or socket path in the proxy's `args` matching the application's host setting. The annotation's value is JSON that maps a container name to the names it depends on, such as `'{"app":["cloud-sql-proxy"]}'`. [Revision annotations](https://cloud.google.com/run/docs/reference/rest/v1/ObjectMeta)

| Dependency annotation | Probe on the proxy | Reading |
| --- | --- | --- |
| Missing | Any | Both containers start concurrently. The race is expected |
| App depends on proxy | Missing | The proxy starts first, but the app does not wait for it to listen. The race remains, shorter |
| App depends on proxy | Present | The app starts after the proxy's probe passes. A refused connection now points elsewhere |

## Check 2: read the start order from the logs

Each container entry carries the instance ID, so the start sequence of one instance can be read in order:

```
gcloud logging read \
  'resource.type="cloud_run_revision"
   AND resource.labels.service_name="orders-api"
   AND resource.labels.revision_name="REVISION"
   AND labels.instanceId="INSTANCE_ID"' \
  --project shop-prod --order=asc --limit=100 \
  --format='value(timestamp, labels, textPayload, jsonPayload.message)'
```

`labels.instanceId` identifies the instance in each container log entry. The proxy's messages and the application's differ enough to tell apart by their text, so the order on one instance reads straight from the timestamps. If the application's refused connection comes before the proxy's listening message, the race happened. [Cloud Run logs](https://cloud.google.com/run/docs/logging)

## Fix the start order

This changes the service and creates a new revision. Export the service, add the annotation and a TCP startup probe on the port the proxy listens on, and replace it:

```
spec:
  template:
    metadata:
      annotations:
        run.googleapis.com/container-dependencies: '{"app":["cloud-sql-proxy"]}'
    spec:
      containers:
      - name: app
        image: APP_IMAGE
        ports:
        - containerPort: 8080
        env:
        - name: DB_HOST
          value: 127.0.0.1
      - name: cloud-sql-proxy
        image: PROXY_IMAGE
        args: ["--private-ip", "--port=5432", "shop-prod:europe-west1:orders-db"]
        startupProbe:
          tcpSocket:
            port: 5432
          periodSeconds: 1
          failureThreshold: 30
```

```
gcloud run services describe orders-api --project shop-prod --region europe-west1 \
  --format export > service.yaml
# edit service.yaml as above, then:
gcloud run services replace service.yaml --project shop-prod --region europe-west1
```

The proxy's arguments follow Google's sidecar example for GKE, where `--port` sets the TCP port and `--private-ip` connects over the instance's private IP; a private IP connection also needs the revision's VPC egress. A TCP startup probe succeeds once Cloud Run can open a connection to the port. [Proxy sidecar arguments](https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine#proxy-sidecar-pattern) A probe that does not pass within `failureThreshold` times `periodSeconds`, at most 600 seconds, shuts the container down. [Startup probes](https://cloud.google.com/run/docs/configuring/healthchecks) · [`gcloud run services replace`](https://cloud.google.com/sdk/gcloud/reference/run/services/replace)

Shutdown has the reverse problem. Before shutting down an instance, Cloud Run sends `SIGTERM` to all containers at once and `SIGKILL` 10 seconds later. A proxy that exits on `SIGTERM` can close connections the application still needs to finish its last requests; configure the proxy, through its own startup options, to keep serving through that period. [Instance shutdown](https://cloud.google.com/run/docs/container-contract)

## Decide: sidecar or built-in connection

Cloud Run's built-in Cloud SQL connection embeds the Cloud SQL Auth Proxy in the platform and mounts a Unix socket at `/cloudsql/INSTANCE_CONNECTION_NAME`. You add it with `--add-cloudsql-instances`, there is no container to order, and every new revision keeps the connection unless a deploy changes it. The first generation execution environment embeds proxy v1, which limits the instances it can reach to the per-instance CA mode. [Connect from Cloud Run](https://cloud.google.com/sql/docs/postgres/connect-run)

A sidecar earns its extra configuration when you need the proxy's own startup options: whether it listens on TCP or a Unix socket, which credentials it uses, and which IP address type it connects with. Running it also makes you choose and update the proxy version. [Proxy startup options](https://cloud.google.com/sql/docs/postgres/sql-proxy#proxy-startup-options)

| You need | Choose |
| --- | --- |
| A connection over the instance's public IP with IAM authorization, nothing else | The built-in connection |
| Proxy options the built-in connection does not take, such as connecting over private IP through the proxy | A sidecar, with a dependency and a startup probe |
| No proxy at all | A language connector, or a private IP connection through VPC egress |

## A worked fixture: one sidecar, two revisions

The fixture is illustrative. `orders-api-00021` replaces the built-in connection with a proxy sidecar named `cloud-sql-proxy`, listening on `127.0.0.1:5432` and connecting to `shop-prod:europe-west1:orders-db` over private IP. The application runs a warm-up query at start and exits if it fails.

**Outcome A: `orders-api-00021`.** The revision has no `container-dependencies` annotation and no probe on the proxy. The deploy at 10:00:00 UTC fails. One instance's log:

| Time (UTC) | Container | Entry |
| --- | --- | --- |
| 10:00:03.120 | `app` | Warm-up query: connection to `127.0.0.1:5432` refused |
| 10:00:03.135 | `app` | Process exits with status 1 |
| 10:00:03.910 | `cloud-sql-proxy` | Listening on `127.0.0.1:5432` for `shop-prod:europe-west1:orders-db` |

The application tried 0.8 seconds before the proxy listened. The traffic stays on `orders-api-00020`.

**Outcome B: `orders-api-00022`.** The team adds `{"app":["cloud-sql-proxy"]}` and the TCP probe above. On the new instance, the proxy logs that it is listening at 10:20:04.020, the probe passes, `app` starts at 10:20:04.880, and its warm-up query succeeds at 10:20:05.310. Ten instances started over the next hour, and none logs a refused connection. The revision takes traffic.

Had the team added only the annotation, `app` would have started after the proxy container started rather than after it listened, and the race would have remained on slower starts.

## Where the checks mislead

A TCP probe shows that the proxy accepts connections on its port. It does not show that the proxy can reach the instance or that its service account has the Cloud SQL Client role; those failures arrive on the first query: an unreachable instance at [stage 1](/learn/cloud-run-cloud-sql-connection-errors/#stage), a missing role at stage 2.

An application that retries its first connection hides the race behind a slow first request. The absence of startup errors does not show that the order is right; read the declared dependencies.

## Questions

### Why does my app start before the Cloud SQL Auth Proxy sidecar on Cloud Run?

Containers without dependencies start concurrently. Add a container dependency from the app to the proxy, and give the proxy a startup probe so Cloud Run waits for it to pass.

### Is the container-dependencies annotation enough on its own?

No. Without a startup probe on the dependency, Cloud Run starts the containers in the listed order even if the dependency has not started successfully.

### Do I need the Auth Proxy sidecar if I use Cloud Run's Cloud SQL connection?

No. The built-in connection runs the proxy for you and mounts a Unix socket. Add a sidecar only for proxy options the built-in connection does not offer.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Cloud Run cannot reach Cloud SQL: revision, identity or connection?](/learn/cloud-run-cloud-sql-connection-errors/)
    
    Broken dependencies The Proofline team November 23, 2026 10 min read
    
-   ### [A Cloud Run revision that is not ready: the container or its startup calls](/learn/cloud-run-revision-not-ready/)
    
    Deployment failures The Proofline team November 20, 2026 9 min read
