advanced
Cloud SQL
Operate managed PostgreSQL, MySQL, or SQL Server with backups, replicas, connection pooling, maintenance, and private networking.
Cloud SQL provides managed PostgreSQL, MySQL, or SQL Server with automated backups, patching, replicas, and private IP access. Node.js services typically connect through a pooler because serverless and autoscaled instances open many short-lived connections.
import pg from 'pg';
const pool = new pg.Pool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: 'app',
max: 10,
idleTimeoutMillis: 30_000,
});
| Concern | Practice | |---------|----------| | Connection limits | Pool at app tier or Cloud SQL Auth Proxy / PgBouncer | | Failover | Understand regional HA versus zonal instances | | Migrations | Run in CI with backward-compatible steps | | Secrets | Secret Manager or mounted secrets, not baked into images |
Test restore drills, index strategy, and maintenance windows before relying on HA marketing slides.
On interviews: connection pooling with Cloud Run; read replicas and replication lag; private IP versus public authorized networks; backup PITR and restore testing.
Common pitfalls: one connection per request without pooling; ORM migrations that lock large tables at deploy; treating replica reads as strongly consistent.
The trade-off is reduced DBA toil versus less tuning freedom, connection ceilings, and vendor-specific failover behavior.
Checklist:
- Pool connections from every Node.js runtime tier.
- Prefer private IP and least-privilege DB users.
- Run reversible migrations with monitoring on deploy.
- Schedule and test backup restores regularly.