Two ways for Cloud Run to reach private IPs such as Cloud SQL, Memorystore and internal services: how each works, what it costs, how many IP addresses it needs, and which to use with Cloud NAT.

Cloud Run runs outside your VPC by default, so a service that needs Cloud SQL on a private IP, a Memorystore instance, or an internal API behind an internal load balancer needs a path into the VPC. For years the only answer was a Serverless VPC Access connector, a small managed group of VMs that forwards traffic into the VPC.
Direct VPC egress, generally available since 2024, is the second option. It places Cloud Run instances on a subnet of your VPC directly, with no connector VMs to pay for or size. It is the better default for most services, with two exceptions to check before you switch: IP address consumption and startup time behind Cloud NAT.
Google keeps a comparison of the two alongside the setup guides.
Create or pick a subnet with room to grow. Cloud Run reserves addresses in blocks and uses roughly twice the number of running instances, and the Direct VPC docs require at least a /26. A service that can scale to 100 instances wants a /24.
private-ranges-only sends RFC 1918 and other private destinations through the VPC and everything else straight to the internet. all-traffic sends everything through the VPC, which you need for a NAT gateway or for egress firewall rules on internet traffic. The network tag lets you write firewall rules that allow only the api service to reach, say, port 5432 on the database.
Direct VPC egress has limits that matter in some setups: a quota caps how many instances per revision can use it, connections can take a minute or more to establish when an instance starts, and VPC Flow Logs do not show the revision name. Add a startup probe that opens a connection to your database, so instances only take traffic once the path works.
A connector needs its own /28 subnet and runs between a minimum and maximum number of instances of a chosen machine type.
Connector instances are billed as Compute Engine VMs even when the service is idle, and a connector does not scale back down once it has scaled up, as the Serverless VPC Access docs note. Size the maximum for peak throughput, and replace the connector if it grows past what you need.
Partners that allowlist your IP need traffic to leave through a Cloud NAT gateway with a reserved address. Both methods support it with --vpc-egress=all-traffic. Google's Direct VPC page warns of cold start delays of 30 seconds or more when Direct VPC egress is used with Cloud NAT and recommends a connector for that case, so services that scale from zero and call an allowlisted API are the main reason to keep a connector today.
Best fit: Direct VPC egress for private access to Cloud SQL, Memorystore and internal services; a connector when you route all traffic through Cloud NAT and startup time matters.
Encore brings infrastructure from code. When you declare a database or a cache and deploy to GCP, Encore creates a dedicated project and VPC for the environment, provisions Cloud SQL and Memorystore on private addresses, and connects the Cloud Run services to that VPC so they reach them without public IPs, as described in the GCP infrastructure docs. The project permissions Encore asks for include roles/vpcaccess.admin to manage Serverless VPC Access connectors, listed in the connect your cloud account docs.
package sessions
import (
"time"
"encore.dev/storage/cache"
"encore.dev/storage/sqldb"
)
// Cloud SQL and Memorystore on private IPs in the environment's VPC.
var db = sqldb.NewDatabase("sessions", sqldb.DatabaseConfig{Migrations: "./migrations"})
var cluster = cache.NewCluster("sessions", cache.ClusterConfig{
EvictionPolicy: cache.AllKeysLRU,
})
type Session struct {
UserID string `json:"user_id"`
}
var Active = cache.NewStructKeyspace[string, Session](cluster, cache.KeyspaceConfig{
KeyPattern: "session/:key",
DefaultExpiry: cache.ExpireIn(30 * time.Minute),
})
For a static outbound IP, the static IP guide uses the same pieces as above: create a Cloud NAT gateway with a reserved IP in the Encore-provisioned VPC, then set VPC egress to All traffic on the environment's Infrastructure page in the Encore Platform dashboard and deploy. Encore leaves the NAT gateway and reserved IP you created untouched on later deploys.
An agent adding a cache or a second database to a service writes the declaration in Go and tests it against local infrastructure; the private networking that connects it in production is the same for every resource, so there is no connector or subnet to add in the pull request.
Best fit: teams on GCP who want Cloud Run services on private networking to Cloud SQL and Memorystore from the first deploy, with a documented path to a static egress IP.
Use Direct VPC egress for new Cloud Run services that need private IPs, with a /24 or larger subnet and a startup probe. Keep or add a connector when all traffic goes through Cloud NAT and cold starts matter, or when your VPC cannot spare the addresses. On Encore, private connectivity to declared databases and caches is set up per environment, and the egress setting is a dashboard option.
Direct VPC egress gives each Cloud Run instance an IP address in a subnet of your VPC, so traffic to private IPs goes straight onto the network with no connector in between. You choose the network and subnet on the service and set vpc-egress to private-ranges-only or all-traffic.
Usually. A Serverless VPC Access connector runs at least two VM instances that you pay for around the clock, while Direct VPC egress has no instances of its own and you pay only standard network charges. The trade-off is IP addresses: Direct VPC needs a subnet of at least /26 and uses about two addresses per running instance.
Yes. It works, but Google's documentation notes cold start delays of 30 seconds or more on instance startup when Direct VPC egress is combined with Cloud NAT, and recommends Serverless VPC Access connectors with Cloud NAT for better startup performance. Set egress to all-traffic in either case.
Encore provisions a VPC per environment and connects Cloud Run services to it so they reach Cloud SQL and Memorystore on private addresses. The VPC egress setting is exposed in the Encore Platform dashboard, where switching it to All traffic plus a Cloud NAT gateway gives services a static outbound IP.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.