Every team I've worked with has a "dev, test, prod" diagram somewhere. And almost every one of those diagrams leaves out the place where most of the real work happens: the developer's laptop.

That's a mistake. Your laptop is where the schema gets designed, where queries get rewritten ten times, and where you find out your idea doesn't work. If it's treated as a scratchpad instead of a real environment, you get the classic problem. Everything works locally, then breaks the moment it hits the cloud.

In this post, I'll walk through the workflow I'd use for a PostgreSQL app that ends up on AlloyDB. Three stages, one schema, one connection string pattern, and as few surprises as possible:

  1. Local: PostgreSQL in Docker on your laptop
  2. Shared test: AlloyDB Express, cheap and quick to spin up
  3. Production: full AlloyDB

I'll also be honest about the gaps between these stages, because that's where things usually go wrong.

The rule that makes this work

Before any setup, here's the one idea the whole workflow depends on:

Your app should never know which stage it's running in.

Same SQL. Same migration files. Same connection pattern. The only thing that changes between stages is one environment variable. If you find yourself writing if (env === "prod") around database code, something has leaked, and it will bite you later.

Keep that in mind. Every decision below is about protecting it.

Stage 1: Your laptop

Match the version first

AlloyDB Express runs PostgreSQL 18 only. So the first thing I'd do is make sure my laptop runs 18 too. Version drift is the quietest bug there is. A query planner change or a new function in one version can make something work locally and fail in the cloud, or the other way around.

Here's a docker-compose.yml that gives you PostgreSQL 18 with pgvector already installed:

services: db: image: pgvector/pgvector:pg18 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: localdev POSTGRES_DB: app ports: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data volumes: pgdata: 

Start it:

docker compose up -d 

Your local connection string:

export DATABASE_URL="postgres://postgres:localdev@127.0.0.1:5432/app?sslmode=disable" 

Remember that 127.0.0.1:5432. We're going to keep using it.

Use migrations from day one

I know it's tempting to just run CREATE TABLE in a SQL editor while you're exploring. Do that for an hour if you want. But the moment the schema starts to settle, move it into migration files. Migrations are the thing that carries your schema from the laptop to production. Without them, every stage drifts a little.

I like dbmate for this because it uses plain SQL files and reads DATABASE_URL, which fits the "only one variable changes" rule perfectly.

dbmate new create_products 

That creates a file in db/migrations/. Fill it in:

-- migrate:up CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE products ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, description TEXT, price NUMERIC(10,2), embedding VECTOR(768) ); -- migrate:down DROP TABLE products; 

Run it:

dbmate up 

Any migration tool works here. Flyway, Liquibase, Prisma, Alembic, whatever your team already uses. What matters is that the schema lives in version control, not in someone's memory.

The gap nobody warns you about: AlloyDB-only features

Here's where most "local to cloud" guides stop being useful. AlloyDB has features plain PostgreSQL doesn't have. The big one for AI apps is the embedding() function from the google_ml_integration extension, which lets you create vectors directly in SQL by calling Vertex AI models.

That's great in the cloud. On your laptop, the extension doesn't exist, so this migration would fail:

CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE; 

You have a few choices:

  • Create embeddings in your app code instead of SQL. This works everywhere, but you give up one of the nicest AlloyDB features.
  • Keep separate SQL for local and cloud. This breaks the "app doesn't know where it runs" rule.
  • Write one migration that adapts to where it runs. This is what I'd do.

Here's that migration:

-- migrate:up DO $$ BEGIN IF EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'google_ml_integration') THEN -- On AlloyDB: use the real thing CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE; ELSE -- On a laptop: a fake embedding() with the same shape EXECUTE $fn$ CREATE OR REPLACE FUNCTION embedding(model_id TEXT, content TEXT) RETURNS REAL[] LANGUAGE sql IMMUTABLE AS $body$ SELECT array_agg( (('x' || substr(md5(content || i::text), 1, 8))::bit(32)::int / 2147483647.0)::real ORDER BY i) FROM generate_series(1, 768) AS i $body$ $fn$; END IF; END $$; -- migrate:down DROP FUNCTION IF EXISTS embedding(TEXT, TEXT); 

On AlloyDB, it installs the real extension. On your laptop, it creates a stand-in function with the same name and the same output size. The stand-in returns a made-up vector based on a hash of the text. The same text always gives the same vector, so your tests are repeatable.

Now this query runs unchanged in all three stages:

UPDATE products SET embedding = embedding('text-embedding-005', name || '. ' || description)::vector; 

Be clear about what the fake does and doesn't do. It lets you test that your SQL runs, your schema fits, your app handles the results, and your indexes build. It does not give you meaningful search results. "Waterproof jacket" and "rain shell" won't land near each other locally. That's fine. Checking whether search results actually make sense is exactly what the next stage is for.

The same thinking applies to indexes. AlloyDB has ScaNN, which plain Postgres doesn't. I'd start with an HNSW index from pgvector, because it works the same on your laptop and on AlloyDB:

CREATE INDEX products_embedding_idx ON products USING hnsw (embedding vector_cosine_ops); 

When you're in production and want to try ScaNN, add it as its own migration and test it there.

Stage 2: AlloyDB Express for shared testing

Your laptop is great for you. It's not great for your team. You need a shared place where teammates, a CI pipeline, or a product manager can see the real thing, with real embeddings and real search results.

That used to mean a staging database running all month for something that gets used a few hours a week. AlloyDB Express is a much better fit. It's ready in about 2 seconds, it scales compute to zero when nobody uses it, and it has the full AlloyDB AI feature set even on the smallest size.

Create it

  1. In the Google Cloud console, go to AlloyDB for PostgreSQL.
  2. On the Get started page, find the AlloyDB Express card and click Create cluster.
  3. Enter a Cluster ID (I'll use app-test), a Password, and a Region.
  4. Click Create cluster.

Express is only in seven regions right now: asia-east1, asia-east2, asia-northeast1, asia-southeast1, australia-southeast1, europe-west2, and us-west1. In the US, that means us-west1.

Then give AlloyDB permission to call Vertex AI, so the real embedding() works. Go to IAM & Admin, then IAM, turn on Include Google-provided role grants, click Grant access, and give service-YOUR_PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com the Vertex AI User role.

The Express settings worth knowing

Express keeps things simple, but there are a few settings and fixed values that matter for a shared test environment:

  • Compute size. You get either 1 vCPU with 4 GB RAM, or 2 vCPUs with 8 GB RAM. New instances start at 1 vCPU. If your test suite feels slow, bump it to 2. You only pay while it's awake either way.
  • Scale to zero. When it's idle, compute goes to zero. The next connection wakes it up in about 20 seconds. For CI, that means the first test might be slow. Add a retry or a short warm-up step to your pipeline instead of letting the first test fail.
  • Connectivity. Express supports public DNS and Private Service Connect. It doesn't support a classic public IP. The console turns on both public DNS and Private Service Connect for you.
  • Authorized networks. If you want to connect with plain psql, open your cluster, go to Connectivity, click Edit, and under Authorized external networks click Use my IP. For team use, I'd skip this and use the Auth Proxy instead (more on that next).
  • Authentication. You can use a regular username and password, or IAM database authentication. For a shared team database, IAM auth is nicer because you're not passing a password around in Slack. Password complexity rules are on by default.
  • Connections are fixed at 200. The max_connections flag is locked, and changing it does nothing. Fine for testing, but keep it in mind if your CI runs a lot of parallel jobs.
  • Storage stops at 20 GB. When you hit it, writes stop. Keep test data small and reset it often.
  • No backups. Treat this database as disposable. Everything in it should be recreatable from your migrations and seed scripts.

Keep the same connection string

Here's my favorite part of this workflow. Remember 127.0.0.1:5432? We're going to keep it.

The AlloyDB Auth Proxy runs on your machine (or in CI) and opens a secure tunnel to AlloyDB. Your app connects to localhost like always, and the proxy handles encryption and IAM authentication.

./alloydb-auth-proxy \ "projects/YOUR_PROJECT/locations/us-west1/clusters/app-test/instances/YOUR_INSTANCE" \ --public-ip 

The --public-ip flag is needed for Express over public DNS. Now:

export DATABASE_URL="postgres://postgres:YOUR_PASSWORD@127.0.0.1:5432/postgres" dbmate up 

Same migration tool. Same migration files. Same host and port. This time, the DO block finds google_ml_integration, installs the real extension, and skips the fake function.

Stop your local Docker database first, or run the proxy on a different port with --port 5433, since they'll both want 5432.

Use it for what your laptop can't do

This is the stage where you check the things the fake embedding can't tell you:

SELECT name, embedding <=> embedding('text-embedding-005', 'something to keep me dry on a rainy hike')::vector AS distance FROM products ORDER BY distance LIMIT 3; 

If the results make sense here, your search actually works. If they don't, you found it before your users did.

A good habit: add a small set of "search quality" checks to your CI that run against Express. For example, "searching for rain gear should return the jacket in the top 3." They're cheap to run, and they catch things unit tests never will.

Stage 3: Full AlloyDB for production

You have two ways to get here.

Option A: Upgrade your Express cluster in place. Go to your cluster, and under Cluster details next to Cluster ID, click Upgrade. Your data, users, and connection string stay the same. This makes sense if your test environment has slowly become the real thing. It happens more often than people admit.

Option B: Create a fresh production cluster and run your migrations. This is what I'd usually do. Production gets its own clean cluster, built from the same migration files, and your Express test environment stays cheap and disposable. Keeping test and production separate is good practice anyway.

Either way, the connection pattern doesn't change. In Cloud Run, run the Auth Proxy as a sidecar, and your app still talks to 127.0.0.1:5432. Or connect over private networking if that fits your setup better. Your SQL and migrations don't need to know.

Production is also where you turn on everything Express didn't have: automated backups and point-in-time recovery, high availability with a standby node, read pools, and room to grow past 2 vCPUs and 20 GB. That's also the moment to try ScaNN, in its own migration, measured against the HNSW index you already have.

What each stage costs

Since I spend a lot of my time on FinOps, I can't write a post like this without talking about money. The nice thing about this workflow is that cost grows with how real the environment is:

Stage What you pay for Rough cost
Laptop Nothing Free
AlloyDB Express Compute per second while awake, storage all the time, embedding calls Often free or close to it. The free tier gives 50 compute units and 2 GB of storage a month for the first 12 months
AlloyDB production Compute per hour, always on, plus storage, backups, and HA if you turn it on This is where real spend starts

Two cost tips:

  • Do most of your work locally. Every query you tune on your laptop is one you don't pay to tune in the cloud.
  • Watch embedding calls in Express. The database might be nearly free, but every embedding() call is a paid Vertex AI request. If your CI re-embeds the whole test dataset on every run, that adds up quietly. Seed once, then reuse.

Limitations and caveats

  • AlloyDB Express is in preview. There's no SLA, and features and pricing can change.
  • PostgreSQL 18 only on Express. If your production AlloyDB runs an older version, test on that version too.
  • The fake embedding() is for development only. It checks that your code runs, not that your search is good. Never let it near a real environment. The DO block guards against this, but review it anyway.
  • Extension differences go beyond embeddings. If you use other AlloyDB-only features, like the columnar engine, you'll need the same "detect and adapt" approach for each one.
  • Express limits are real: 20 GB storage cap, no backups, no HA, 200 connections, and about 20 seconds to wake up from zero.
  • Local Docker isn't AlloyDB. Performance numbers from your laptop mean very little. Do load testing on the real thing.
  • Express is only in seven regions right now.

Wrapping up

The point of this workflow isn't Docker or dbmate or any one tool. It's three habits:

  1. Treat your laptop as a real environment, matched to the cloud version.
  2. Carry your schema forward in migrations, and handle cloud-only features in one place.
  3. Keep the connection pattern the same everywhere, so your app never knows where it's running.

Do that, and "it works on my laptop" stops being a warning and starts being a pretty good sign.

If you've found other gaps between local PostgreSQL and AlloyDB, I'd like to hear about them in the comments. I'm sure I haven't hit them all yet.

Sources