Tech Interview RoomStudy guides

Cloud SQL

What is Cloud SQL and when would you choose it over running your own database or other Google Cloud databases?

Beginner · 2 min read · Lesson 1 of 5 in Cloud SQL

Cloud SQL is Google Cloud's fully managed relational database service for MySQL, PostgreSQL and SQL Server. Google runs the servers, operating system, database installation, patching, backups, replication and failover; you manage schemas, queries, users and sizing.

What you get

  • Automated daily backups and point-in-time recovery (from transaction logs).
  • High availability (a regional instance with a standby in another zone and automatic failover).
  • Read replicas in the same or other regions, and cross-region replicas for disaster recovery.
  • Private IP inside your VPC, IAM integration, encryption at rest and in transit, customer-managed keys.
  • Maintenance windows, storage auto-increase, Query Insights for performance.
  • Two editions: Enterprise and Enterprise Plus (higher availability SLA, faster failover, data cache, larger machines).

Choosing among Google Cloud databases

  • Cloud SQL: standard MySQL/PostgreSQL/SQL Server for typical OLTP apps up to a single large primary (vertical scaling + read replicas). Easiest lift-and-shift.
  • AlloyDB for PostgreSQL: PostgreSQL-compatible, higher performance and a columnar engine for analytics on operational data; costs more.
  • Spanner: globally distributed, horizontally scalable SQL with strong consistency (huge scale, multi-region writes).
  • Firestore / Bigtable: NoSQL documents and wide-column at massive scale.
  • BigQuery: analytics warehouse, not OLTP.

Run your own database on Compute Engine or GKE only if you need unsupported extensions, versions or OS-level control.

Example

bash
# Create a PostgreSQL 16 instance with HA, private IP and PITR
gcloud sql instances create orders-db \
  --database-version=POSTGRES_16 \
  --edition=ENTERPRISE \
  --tier=db-custom-4-16384 \
  --region=asia-south1 \
  --availability-type=REGIONAL \
  --network=projects/my-proj/global/networks/prod-vpc --no-assign-ip \
  --enable-point-in-time-recovery \
  --backup-start-time=20:30 \
  --maintenance-window-day=SUN --maintenance-window-hour=22

gcloud sql databases create orders --instance=orders-db
gcloud sql users create app --instance=orders-db --password='use-secret-manager'

Follow-up questions interviewers ask

Try answering each one before you open it.

What does "managed" not cover?

Query and schema design, indexes, connection limits and pooling, sizing the machine and storage, choosing HA and replicas, testing restores, and application-level retries during failover and maintenance remain your responsibility.