AlloyDB Express 原型從週五開發到週一上線的成本與升級指南
Build It Friday, Ship It Monday: Taking an AlloyDB Express Prototype to Production
作者以 TrailBuddy 示範如何把 AlloyDB Express 原型部署至正式環境,並追蹤從沒有用戶到流量增長期間的成本與升級決策。按 2 vCPU 持續運行估算,Express 每月運算費約 $162,升級至單區 AlloyDB(2 vCPU/16 GB)約 $227。
Most side projects die in one of two places. Either they never get built because setting up infrastructure eats the whole weekend, or they get built on something cheap and throwaway, and then the founder has to rebuild everything the moment real users show up.
AlloyDB Express is Google Cloud's attempt at fixing both. It gives you a PostgreSQL database in seconds that scales to zero when nobody's using it, and when you're ready, you upgrade it in place to full AlloyDB. No migration, no new connection string.
I wanted to see how that plays out over the life of a real product, not just a hello world. So in this post I follow one small app from a Friday night idea to its first real users, and I look at the bill at every stage. I spend most of my day job on FinOps, so the money side is what I care about most here: what it costs, what signals to watch, and when paying more is actually the right call.
The app: TrailBuddy
Here's the idea. TrailBuddy helps people find a hiking partner. You write a short bio like "I like slow sunrise hikes, about 5 miles, and I always bring too many snacks," and the app finds people who sound like a good match. It's not keyword matching. It's matching by meaning, using vector search.
The stack:
- Next.js for the web app and API routes
- Cloud Run to host it, because it scales to zero
- AlloyDB Express for the database, with vector search built in
Every piece in this stack can go idle and stop charging you for compute. That matters a lot when you have zero users.
Friday night: build it
Create the database (about 2 minutes)
In the Google Cloud console:
- Go to AlloyDB for PostgreSQL. You land on the Get started page.
- On the AlloyDB Express card, click Create cluster.
- Enter a Cluster ID (I used trailbuddy-db), a Password for the postgres user, and a Region.
- Click Create cluster.
A quick note on regions. Express is only in seven regions right now: asia-east1, asia-east2, asia-northeast1, asia-southeast1, australia-southeast1, europe-west2, and us-west1. If you're in the US, us-west1 is your only option. Put your Cloud Run service in the same region, because cross-region traffic adds latency and can add data transfer charges.
The console opens AlloyDB Studio when it's done. Paste this in and click Run:
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE;
CREATE TABLE hikers (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
city TEXT,
bio TEXT NOT NULL,
bio_vector VECTOR(768),
created_at TIMESTAMPTZ DEFAULT now()
);
To let AlloyDB create embeddings, give its service agent the Vertex AI User role. Go to IAM & Admin, then IAM, turn on Include Google-provided role grants, click Grant access, and add service-YOUR_PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com with the Vertex AI User role. It can take a few minutes to start working.
The matching query
This is the whole "AI" part of the app. One query:
SELECT id, name, city,
bio_vector <=> embedding('text-embedding-005', $1)::vector AS distance
FROM hikers
ORDER BY distance
LIMIT 5;
When someone signs up, you store their embedding once:
INSERT INTO hikers (name, city, bio, bio_vector)
VALUES ($1, $2, $3, embedding('text-embedding-005', $3)::vector);
The Next.js side
Here's a simple API route for matches, using the pg package:
// app/api/match/route.js
import { Pool } from "pg";
const pool = new Pool({
host: "127.0.0.1",
port: 5432,
user: "postgres",
password: process.env.DB_PASS,
database: "postgres",
max: 5,
});
export async function POST(req) {
const { bio } = await req.json();
const { rows } = await pool.query(
`SELECT id, name, city,
bio_vector <=> embedding('text-embedding-005', $1)::vector AS distance
FROM hikers ORDER BY distance LIMIT 5`,
[bio]
);
return Response.json({ matches: rows });
}
Notice the host is 127.0.0.1. The docs list language connectors for Go, Python, and Java with Express, but not Node.js. So for a Next.js app, I run the AlloyDB Auth Proxy as a sidecar container next to the app in Cloud Run. The proxy handles encryption and IAM auth, and the app just talks to localhost. The proxy needs the --public-ip flag to reach an Express instance over public DNS.
Also notice max: 5 on the pool. Keep that in your head. It comes back later.
Deploy to Cloud Run
Cloud Run's multi-container support lets you deploy the app and the proxy together. The short version of the service setup:
- Container 1: your Next.js app, listening on port 8080
-
Container 2: the AlloyDB Auth Proxy image, with arguments pointing at your instance URI (
projects/PROJECT_ID/locations/us-west1/clusters/trailbuddy-db/instances/INSTANCE_ID) and the--public-ipflag - The Cloud Run service account needs the AlloyDB Client and Service Usage Consumer roles
Before you hit deploy, add two things that are pure FinOps hygiene:
--max-instances=4 \
--labels=app=trailbuddy,env=prototype,owner=yourname
--max-instances is your cost ceiling. If a bot hammers your URL at 3 a.m., Cloud Run won't scale to 100 instances and run up a bill. Labels are how you'll find this app's costs later in billing reports. It takes ten seconds now and saves you an hour of digging later.
Saturday: set up the money guardrails
This is the step everyone skips, and it's the one I care about most. Do it before you tell anyone about your app.
1. Budget alert
- In the console, go to Billing, then Budgets & alerts.
- Click Create budget and scope it to your project.
- Set the amount to something you'd be okay losing, like $25.
- Keep the alerts at 50%, 90%, and 100%, and click Finish.
A budget alert doesn't stop spending. It just emails you. But for a weekend project, an email at $12.50 is usually all you need.
2. Billing export to BigQuery
- Go to Billing, then Billing export.
- Under BigQuery export, click Edit settings for Detailed usage cost.
- Pick a project and create a dataset like
billing_export.
It only collects data from the moment you turn it on, so turn it on early. Later, when you're trying to work out what each user costs you, you'll be glad you have the history.
3. Know what "idle" really costs
Here's the part of Express pricing that's easy to miss. Compute scales to zero, but storage doesn't. You pay for storage every hour, awake or asleep.
| What | How it's billed | Free each month |
|---|---|---|
| Express compute | Per second while awake. 1 vCPU = 1 compute unit, 2 vCPU = 2 | 50 compute unit hours, first 12 months |
| Express storage | Per GB used, all the time | 2 GB, first 12 months |
| Vertex AI embeddings | Every embedding() call |
None |
| Cloud Run | Requests and CPU time | Monthly free tier |
At launch, Google's announcement priced compute at around $0.115 per compute unit hour and storage at $0.30 per GB-month. Prices can vary by region and change after preview, so check the current pricing page before you plan around these numbers.
Monday: ship it
You post TrailBuddy in a couple of hiking groups. A few dozen people sign up. Here's what the bill looks like in that first month, using a 1 vCPU instance and those launch prices:
- The database is awake maybe 2 to 3 hours a day while people browse. That's roughly 60 to 90 compute unit hours. The first 50 are free, so you're paying for 10 to 40. Call it $1 to $5.
- Storage is under 2 GB. $0.
- A few hundred embedding calls. Cents.
- Cloud Run stays inside the free tier. $0.
So the whole first month comes in around the price of a coffee. That's the real promise of Express. Not that it's fast, but that an idea with no users costs almost nothing to keep alive.
One honest trade-off: after about 15 minutes of no traffic the database pauses, and the next request takes around 20 seconds while it wakes up. For a hobby app, that's fine. For a landing page you just shared with 5,000 people, the first visitor might bounce. Know it's there.
Day 30: people actually show up
A local hiking blog writes about TrailBuddy. Signups jump. Now the bill and the limits start to matter, and this is where FinOps thinking pays off.
Signal 1: the database never sleeps anymore
Scale to zero only saves money if there's quiet time. When you have users in a few time zones, the database stays awake almost all day. Let's do the math for a 2 vCPU instance that's awake 24/7:
- 730 hours x 2 compute units = 1,460 compute unit hours
- Minus 50 free = 1,410
- At $0.115 each, that's about $162 a month in compute
That's still not much. But notice what changed. You're no longer paying for "only when used." You're paying for "always on," just billed by the second. The main reason to be on Express is gone.
Signal 2: the limits start to bite
This is where I'd stop looking at the bill and start looking at risk. Express has hard limits:
- 20 GB of storage, and when you hit it, writes stop. Signups would just fail.
- No backups and no point-in-time recovery. One bad migration and your users' data is gone.
- No high availability, and no SLA. If the zone has a problem, your app is down.
- max_connections is fixed at 200, and changing the flag does nothing.
Remember that max: 5 on the pool? Each Cloud Run instance opens up to 5 connections. If you raise --max-instances to 50 to handle traffic, that's up to 250 connections, which is more than Express allows. Your cost ceiling and your connection ceiling are the same knob. Plan them together.
Signal 3: your unit cost is going up, not down
Here's the FinOps metric I'd actually track: cost per active user. If your billing export is in BigQuery with labels, you can get a rough number with a query like this (adjust the table name to yours):
SELECT
FORMAT_DATE('%Y-%m', DATE(usage_start_time)) AS month,
ROUND(SUM(cost), 2) AS trailbuddy_cost
FROM `your-project.billing_export.gcp_billing_export_resource_v1_XXXXXX`,
UNNEST(labels) AS l
WHERE l.key = 'app' AND l.value = 'trailbuddy'
GROUP BY month
ORDER BY month;
Divide that by your monthly active users. In a healthy setup, the cost per user goes down as you grow. If it's going up, something isn't scaling the way you think. Labels only cover what you labeled, so treat this as a direction, not an exact number.
Day 31: the upgrade
The upgrade itself is the easy part:
- Go to AlloyDB for PostgreSQL, then Clusters, and click your cluster.
- Under Cluster details, next to Cluster ID, click Upgrade.
- Type your cluster ID and click Confirm.
Your data, users, extensions, and connection string all stay the same. Your Next.js code doesn't change at all. If you're on 1 vCPU in a region without C4A machines, the console asks you to resize to 2 vCPUs first.
But before you click, understand what changes on the bill:
- Scale to zero turns off. The instance runs all the time and is billed per hour at normal AlloyDB rates.
- Memory doubles. Express runs 1 vCPU to 4 GB. AlloyDB runs 1 vCPU to 8 GB. So a 2 vCPU instance goes from 8 GB to 16 GB of RAM, and you pay for that memory.
- There's no going back. You can't downgrade to Express later.
Here's a rough comparison using example list rates I saw on the AlloyDB pricing page (about $0.066 per vCPU hour and $0.0112 per GB of memory per hour). Rates vary by region, so plug in your own:
| Setup | Rough monthly compute |
|---|---|
| Express, 2 vCPU, awake 24/7 | About $162 |
| AlloyDB, 2 vCPU / 16 GB, single zone | About $227 |
| AlloyDB, 2 vCPU / 16 GB, with 1-year commitment | About $170 |
| AlloyDB with regional high availability | Roughly double the single-zone number, since it runs a standby node |
So the upgrade isn't free, but it's not a cliff either. For about $65 more a month, you get backups, no 20 GB cap, room to scale up to 288 vCPUs, and the option to add high availability with a 99.99% SLA.
The FinOps moves after the upgrade
Now that you're on regular AlloyDB, a few things open up that weren't available on Express:
- Committed use discounts. Express doesn't support them. Regular AlloyDB does, with 1-year and 3-year options. Once your usage is steady for a couple of months, a 1-year commitment brings that $227 down to around $170. Don't commit in month one, though. Commit once you know your baseline.
- Right-size before you scale. Watch CPU and memory on the cluster's Overview page and in System insights. Don't jump from 2 to 8 vCPUs because one chart spiked.
- Add high availability when downtime costs more than the standby. For a free hobby app, single zone is often fine. Once people pay you, an hour of downtime probably costs more than a month of the standby node.
- Turn on backups right away. This is the one I wouldn't wait on.
My "when to upgrade" checklist
If two or more of these are true, it's time:
- [ ] The database is awake more than about 18 hours a day
- [ ] Storage is past 10 GB and growing
- [ ] You'd be in real trouble if you lost today's data
- [ ] Users are paying you, or you've promised uptime to someone
- [ ] You need more Cloud Run instances than 200 connections can support
- [ ] You need Terraform or Config Connector to manage the database (Express doesn't support them yet)
If none of these are true, stay on Express and enjoy the tiny bill.
Limitations and caveats
Being honest about what this setup can't do:
- AlloyDB Express is in preview. There's no SLA, and support may be limited. Pricing and features can change before general availability.
- It runs PostgreSQL 18 only, on a single zonal instance with 1 or 2 vCPUs.
- No backups, no PITR, no read pools, no HA, no cross-region replication.
- 20 GB storage cap, and writes stop when you hit it.
- The cost numbers in this post are estimates based on launch announcements and example list rates. Run your own numbers in the Google Cloud pricing calculator for your region.
- Embedding calls are billed separately through Vertex AI. If you embed a large dataset or re-embed often, that line can grow faster than the database itself.
- Cold starts are about 20 seconds after the database pauses.
- Node.js isn't in the list of language connectors the Express docs mention, so I used the Auth Proxy sidecar. Check the docs in case that has changed.
Wrapping up
The best thing about this setup isn't any single feature. It's that your infrastructure bill can follow your traction. When nobody uses the app, you pay almost nothing. When people show up, you pay a bit more. And when it's a real business, you upgrade in place and unlock the tools that real businesses need, including the discounts.
Build it Friday. Ship it Monday. Upgrade when the numbers tell you to, not before.
If you try this, I'd like to know what your first-month bill looked like. Drop it in the comments.
Sources
來源:DEV Community · dev.to