Back to Blog
infrastructureInfrastructureGCPSupabasePulumiDevOps

Why We Self-Host Supabase on GCP (And How We Did It)

Supabase is great, but managed hosting isn't always the answer. Here's why we chose to self-host on GCP and built infrastructure-as-code with Pulumi.

Why We Self-Host Supabase on GCP (And How We Did It)

Yes, Supabase runs on Google Cloud if you self-host it: its Docker Compose setup runs on Compute Engine, and it can use Cloud SQL for PostgreSQL as its database. Supabase's guides don't cover that setup, and Cloud SQL brings two limits: no superuser, so you create Supabase's roles yourself, and no pg_graphql, pg_net or Supabase Vault, so the GraphQL API, Database Webhooks and Vault won't work on it.

Still deciding where to run Supabase? Our guide to Supabase hosting options compares Supabase Cloud, a VPS, managed hosts, your own cloud account and Kubernetes, with prices for each.

Supabase has become one of our favorite tools for building applications quickly. The combination of PostgreSQL, real-time subscriptions, authentication, and a beautiful Studio interface is hard to beat.

But for a recent client project, we couldn't use Supabase's managed hosting. The requirements were clear: data residency, VPN-only access to the database, enterprise-grade PostgreSQL, and full control over the infrastructure.

So we self-hosted it on GCP.

Supabase vs Google Cloud SQL

Cloud SQL is Google Cloud's managed PostgreSQL. Google runs the database server, with automated backups, point-in-time recovery, patches in a maintenance window you choose, high availability across zones and a private IP in your network. Supabase is a platform built on PostgreSQL: authentication, file storage, Realtime, Edge Functions and the Studio dashboard come with the database. Supabase Cloud runs in AWS regions, so to run Supabase on Google Cloud you self-host it, and Cloud SQL can be its database.

  • Choose Supabase Cloud for MVPs and most small and mid-sized projects. Supabase runs everything, plans start free with Pro from $25 a month, and once you count engineering time it's usually the cheaper option at that size.
  • Choose Cloud SQL on its own when you need a managed PostgreSQL database and not the rest of Supabase. You can still run Supabase Studio against it as an admin dashboard, as we do.
  • Choose self-hosted Supabase on Cloud SQL when you want Supabase but the database has to sit in your own Google Cloud project, on a private network or in a region Supabase Cloud doesn't offer, and you have the engineering time to run everything else. Cloud SQL's limits still apply: no superuser, and no pg_graphql, pg_net or Supabase Vault.

Our Supabase pricing calculator prices your usage on Supabase Cloud and self-hosted on Google Cloud VMs, engineering time included.

The honest tradeoff

Self-hosting gives you control, and the work that comes with it. Managed Supabase handles:

  • Database backups and point-in-time recovery
  • Security patches and updates
  • Scaling and high availability
  • Monitoring and alerting
  • SSL certificates and networking

When you self-host, all of that becomes your job. For many projects, especially MVPs and early-stage startups, managed hosting is the right choice. Ship fast, validate, and don't spend engineering time on infrastructure.

But sometimes managed doesn't work. And that's when self-hosting makes sense.

When self-hosting makes sense

We recommend going down this path in these cases:

1. Data residency requirements

Our client's data stays in London (europe-west2). Supabase Cloud has a London region too, but the client wanted the database in their own GCP project for compliance and audit purposes.

2. Network isolation

The database should never be accessible from the public internet. We needed VPN-only access with Cloud Armor providing an additional layer of protection.

3. Enterprise PostgreSQL features

GCP's Cloud SQL Enterprise Plus tier offers features that are hard to replicate:

  • Data Cache: automatic caching layer for frequently accessed data
  • Performance-optimized instances: up to 128 vCPUs and 864GB RAM
  • Query Insights: built-in query performance monitoring
  • 99.99% SLA: with regional (multi-zone) deployments

We cover the database setup in full in Cloud SQL PostgreSQL 18 Enterprise Plus: A Complete Setup Guide.

4. Cost predictability at scale

At a certain scale, the economics shift. When you're paying for enterprise PostgreSQL anyway, adding Supabase Studio (which is open source) costs virtually nothing extra.

Our architecture

Self-hosted Supabase on Google Cloud
InternetVPN(Outline)Cloud Armor(Whitelist)Global Load Balancer(SSL Termination)VPCManaged Instance Group(Supabase Studio + postgres-meta)Cloud SQL PostgreSQL 18(Enterprise Plus)Private IP only

Key components:

  • VPN (Outline): self-hosted on a small VM, provides secure access for developers
  • Cloud Armor: whitelists only the VPN server IP
  • VPC firewall: lets only Google's load balancer and health check ranges reach the instances
  • Global Load Balancer: handles SSL termination with Google-managed certificates
  • Managed Instance Group: auto-scaling, auto-healing Supabase Studio containers
  • Cloud SQL Enterprise Plus: PostgreSQL 18 with private networking only

Infrastructure as Code with Pulumi

We chose Pulumi over Terraform for one simple reason: TypeScript.

With Pulumi, we get real programming constructs: loops, conditionals, type safety and IDE autocomplete. No more HCL string interpolation gymnastics.

The code is laid out like this:

├── components/          # Reusable infrastructure modules
│   ├── database.ts      # Cloud SQL component
│   ├── networking.ts    # VPC, subnets, firewall rules
│   ├── loadbalancer.ts  # Global LB with SSL
│   ├── vpn.ts          # Outline VPN server
│   └── service-account.ts
├── services/            # Application deployments
│   └── supabase-studio/ # Studio + postgres-meta
├── config/              # Environment configuration
│   └── secrets.ts       # Infisical integration
└── index.ts            # Main entry point

Component-based architecture

Each infrastructure component is a Pulumi ComponentResource that encapsulates related resources. A simplified version of our database component:

export const DatabasePresets = {
  /** Development: 4 vCPUs, 32 GB RAM, Single-zone */
  dev: {
    tier: "db-perf-optimized-N-4",
    edition: "ENTERPRISE_PLUS",
    availabilityType: "ZONAL",
    diskSize: 250,
    dataCacheEnabled: true,
    deletionProtection: false,
  },
  /** Production: 8 vCPUs, 64 GB RAM, Multi-zone HA */
  prod: {
    tier: "db-perf-optimized-N-8",
    edition: "ENTERPRISE_PLUS",
    availabilityType: "REGIONAL",
    diskSize: 250,
    dataCacheEnabled: true,
    deletionProtection: true,
  },
};

We define presets for each environment, then use them like this:

const database = new Database("database", {
  name: resourcePrefix,
  region: config.region,
  network: networking.vpc,
  privateVpcConnection: networking.privateVpcConnection,
  databaseName: secrets.apply(s => s.infra.postgresDb),
  password: secrets.apply(s => s.infra.postgresPassword),
  preset: config.environment as DatabasePreset, // "dev" or "prod"
});

The preset provides sensible defaults, but any setting can be overridden. This pattern gives us consistency across environments while allowing flexibility when needed.

Private networking

One of our non-negotiables was keeping the database off the public internet. Cloud SQL supports private IP through VPC peering:

// Reserve an IP range for the private connection
this.privateIpRange = new gcp.compute.GlobalAddress(`${resourceName}-private-ip-range`, {
  purpose: "VPC_PEERING",
  addressType: "INTERNAL",
  prefixLength: 16,
  network: this.vpc.id,
});
 
// Create the private connection to Google's service networking
this.privateVpcConnection = new gcp.servicenetworking.Connection(`${resourceName}-private-vpc-connection`, {
  network: this.vpc.id,
  service: "servicenetworking.googleapis.com",
  reservedPeeringRanges: [this.privateIpRange.name],
});

With this in place, the Cloud SQL instance gets a private IP within our VPC. No public IP is ever assigned.

VPN for secure access

We deployed Outline VPN (from the Jigsaw team at Google) on a small e2-small instance. It's lightweight, easy to manage, and works great with the Outline client apps.

The clever bit is the Cloud Armor integration. We whitelist only the VPN server's public IP:

securityPolicy = new gcp.compute.SecurityPolicy(`${resourceName}-security-policy`, {
  rules: [
    // Default: deny all
    {
      action: "deny(403)",
      priority: 2147483647,
      match: {
        versionedExpr: "SRC_IPS_V1",
        config: { srcIpRanges: ["*"] },
      },
    },
    // Allow VPN server
    {
      action: "allow",
      priority: 900,
      match: {
        versionedExpr: "SRC_IPS_V1",
        config: {
          srcIpRanges: [pulumi.interpolate`${vpnPublicIp}/32`],
        },
      },
    },
  ],
});

Now Supabase Studio is only accessible to team members connected to the VPN. Even if someone finds the URL, they can't access it without VPN credentials.

There's no rule for Google's health checks. The probes don't pass through the load balancer, so Cloud Armor never sees them. They need a VPC firewall rule instead (lesson 5 below).

Secret management with Infisical

We use Infisical for secret management. It's like Doppler or HashiCorp Vault, but with a cleaner developer experience.

Secrets are fetched at deployment time and injected into the infrastructure:

export function fetchSecrets(
  clientId: pulumi.Output<string>,
  clientSecret: pulumi.Output<string>,
  environment: string,
): pulumi.Output<AllSecrets> {
  return pulumi.all([clientId, clientSecret]).apply(async ([id, secret]) => {
    const client = new InfisicalSDK({
      siteUrl: "https://eu.infisical.com",
    });
 
    await client.auth().universalAuth.login({
      clientId: id,
      clientSecret: secret,
    });
 
    const infraSecrets = await client.secrets().listSecrets({
      projectId: INFRA_PROJECT_ID,
      environment: environment,
      secretPath: "/",
    });
 
    // Return structured secrets
    return {
      infra: {
        postgresDb: getSecretValue(infraSecrets, "POSTGRES_DB"),
        postgresPassword: getSecretValue(infraSecrets, "POSTGRES_PASSWORD"),
      },
      // ... more secrets
    };
  });
}

This keeps secrets out of our Git repository while still being fully automated. It doesn't keep them out of the Pulumi state: Pulumi records every resource input there, so the database password passed to the database component is stored too. Because the Infisical credentials are secret config values, everything fetched with them is marked secret as well, and Pulumi encrypts those values in the state file instead of storing plain text.

Environment-specific deployments

We run two environments: dev and prod. Same code, different configurations:

SettingDevProd
Database tier4 vCPU / 32 GB8 vCPU / 64 GB
AvailabilitySingle-zoneMulti-zone (HA)
Min instances12
Deletion protectionOffOn
Subnet CIDR10.0.1.0/2410.1.1.0/24

Switching environments is as simple as:

pulumi stack select dev
pulumi up
 
# or
 
pulumi stack select prod
pulumi up

What we haven't covered (yet)

This post focused on the core architecture. There's more to come:

Multi-region

We've since gone multi-region, though not with the read replicas we first planned. Each region now has its own writable PostgreSQL node, kept in sync with pglogical. The full story is in Multi-Region PostgreSQL on GCP.

Cost breakdown

We've since published it. How Much Does Supabase Cost? prices three example setups on Supabase Cloud and the same setups self-hosted on Google Cloud, engineering time included, and Self-Hosted Supabase in Production covers what goes into the bill.

Monitoring and alerting

We're using GCP's built-in monitoring, but there's a lot more we could say about setting up proper observability.

Lessons learned

1. Start with presets

Defining environment presets (dev/prod) upfront saved us countless hours. Every new resource follows the same pattern: sensible defaults with override capability.

2. VPN is worth the complexity

Yes, it's another component to maintain. But for internal tools, the security benefits outweigh the overhead. Plus, Outline is remarkably low-maintenance.

3. Test startup scripts locally

Our Container-Optimized OS instances run startup scripts that pull and configure Docker containers. Testing these locally (using Docker and a mock environment) caught issues that would have been painful to debug on live instances.

4. Private networking takes time

The VPC peering for Cloud SQL private IP can take 5-10 minutes to provision. Plan for this in your deployment scripts and don't be alarmed when pulumi up seems to hang.

5. Health checks need a firewall rule

This caught us initially: the load balancer showed every backend as unhealthy because the health check probes were blocked. The probes don't go through the load balancer, so a Cloud Armor rule can't let them in. They connect straight to each instance's internal IP, and the VPC firewall has to allow them. Google's firewall requirements list 35.191.0.0/16 for the probes and 130.211.0.0/22 plus 35.191.0.0/16 for the load balancer's own traffic, so one rule allowing both ranges on the serving port covers it.

When to go this route

Self-hosting Supabase on GCP makes sense when you:

  • Need data residency or compliance controls
  • Want enterprise PostgreSQL features (Data Cache, high SLA)
  • Require VPN-only or IP-restricted access
  • Have the engineering capacity to manage infrastructure
  • Are at a scale where managed pricing becomes significant

For everyone else, especially early-stage projects, stick with managed Supabase. It's excellent, and your time is better spent on your product.

The rest of the series

Each part of the setup has its own post:

  1. Infrastructure as code with Pulumi
  2. Cloud SQL PostgreSQL 18 on Enterprise Plus
  3. VPN-only access with Cloud Armor
  4. Auto-scaling Supabase Studio
  5. Multi-region PostgreSQL with pglogical

For what self-hosting involves on any cloud (the full set of Supabase services, upgrades, backups and a production checklist), read Self-Hosted Supabase in Production: What It Takes. Handling health data? See Supabase HIPAA cost and BAA terms.

Frequently asked questions

Can Supabase be self-hosted on Google Cloud?

Yes. Supabase's self-hosting guide calls Docker the fastest and recommended way to self-host, and its Docker Compose setup runs on any Linux VM, including Compute Engine. Kubernetes, and so GKE, is covered only by a community project that Supabase doesn't maintain. Self-hosted Supabase is community-supported, so day-to-day help comes from GitHub, Discord and Reddit rather than Supabase's support team.

Our setup splits the stack: Supabase Studio and postgres-meta run on a regional managed instance group, the database is Cloud SQL Enterprise Plus on a private IP, and Studio is only reachable through a VPN.

Can self-hosted Supabase use Cloud SQL for PostgreSQL, and what are the limits?

Partly, and you're on your own when you do. Supabase's Docker setup ships its own Postgres image, and its self-hosting guides don't cover external or managed databases. On Cloud SQL, three things get in the way:

  • No superuser. Cloud SQL doesn't give customers users with the SUPERUSER attribute. The postgres user has CREATEROLE, CREATEDB and LOGIN and belongs to cloudsqlsuperuser, which can create extensions and event triggers (Cloud SQL users and roles).
  • A fixed extension list. You can only install the extensions Cloud SQL supports. pgcrypto, uuid-ossp, pgvector, pg_cron, pg_stat_statements and PostGIS are on it. pg_graphql (behind Supabase's GraphQL API), pg_net (behind Database Webhooks) and Supabase Vault are not.
  • Roles you create yourself. Supabase's services expect roles such as anon, authenticated, service_role, authenticator, supabase_auth_admin and supabase_storage_admin. Supabase's own Postgres image comes with them. On Cloud SQL you create them without superuser rights, then check that each service's migrations still run.

Major version upgrades need planning too. Cloud SQL's in-place upgrade deletes every logical replication slot, including the one Realtime reads from, as we found in our test upgrade from PostgreSQL 14 to 18.

We run Studio and postgres-meta against Cloud SQL. When we needed pg_net for webhooks, we ran it on a self-managed PostgreSQL node on Compute Engine instead, as described in our multi-region post.

Is self-hosting cheaper than Supabase Cloud?

Usually not for a small project. Supabase's Pro plan starts at $25 a month and includes $10 of compute credits (pricing). Self-hosting swaps that for your own cloud bill plus the engineering time for upgrades, backups, monitoring and on-call, and that time is easy to underestimate.

It pays off when you'd be paying for a large PostgreSQL setup anyway, or when you need something managed hosting can't give you, like the database inside your own cloud project. Running PostgreSQL yourself saves the most and needs the most care: our self-managed nodes on Compute Engine cost about $120 to $140 a month each, against the $400 to $500 a month we'd estimated per Cloud SQL replica, but we own their upgrades and backups. Our production guide goes through what to budget for, and How Much Does Supabase Cost? prices three setups both ways.

What do you give up by self-hosting Supabase?

According to Supabase's self-hosting docs, a self-hosted install runs as a single project (Studio doesn't support multiple organizations or projects), most settings live in environment variables, and these platform features aren't available: branching, advanced metrics beyond logs, managed backups and point-in-time recovery, analytics and vector buckets, ETL and the Management API. Support comes from the community.

Putting the database on Cloud SQL gets automated backups and point-in-time recovery back, from Google instead of Supabase (our configuration). The rest is yours to build or do without.

Can a self-hosted Supabase setup support HIPAA work?

It can be part of a HIPAA-compliant system, but self-hosting doesn't make you compliant. Google Cloud signs a Business Associate Agreement, and its list of covered products includes Compute Engine, Cloud SQL, Cloud Storage, Cloud Load Balancing and Cloud Armor. Supabase's HIPAA docs say its HIPAA controls aren't supported out of the box in self-hosted Supabase, so access control, audit logging, encryption, backups and the rest of the safeguards are yours to build and document.

We go through it in Supabase HIPAA Compliance. This isn't legal advice.

Does Supabase offer EU data residency?

Supabase Cloud has several regions in Europe: Ireland, Paris, Frankfurt and Stockholm inside the EU, and London and Zurich outside it, as Supabase's own page points out. For many teams, picking one of those is enough. Our client wanted more than that: the database inside its own Google Cloud project, in London (europe-west2), for compliance and audit reasons. Self-hosting is how you get that.


Building infrastructure with specific compliance or security requirements? We set up and run self-hosted Supabase on Google Cloud as a fixed-scope project.

Sachin Mour
Founder of Pulore, ex-CTO at Hexis
Share:

Want Supabase on your own cloud?

We set up and run self-hosted Supabase on Google Cloud for teams that need control over their data: private networking, managed PostgreSQL, backups and monitoring, all defined as code.