Tech Interview RoomStudy guides

Cloud SQL

How do high availability, failover and read replicas work in Cloud SQL?

Intermediate · 2 min read · Lesson 3 of 5 in Cloud SQL

High availability (regional instance)

--availability-type=REGIONAL creates a primary in one zone and a standby in another zone of the same region. Writes go to a regional persistent disk replicated synchronously to both zones, so a committed transaction is on both. If the primary or its zone fails, Cloud SQL fails over automatically: the standby takes over with the same IP address, typically within about a minute (Enterprise Plus aims for much shorter, and near-zero-downtime planned maintenance).

During failover, open connections drop: applications must retry with backoff and use pools that validate and recreate connections (HikariCP does).

Read replicas

Asynchronous copies for scaling reads or analytics, in the same region or cross-region. They can lag; route read-after-write traffic to the primary. A replica can be promoted to a standalone primary (a manual step, for example in disaster recovery or a migration). Replicas can themselves be made HA.

Disaster recovery

Cross-region replicas plus a runbook (or Enterprise Plus's advanced DR with switchover/failover to a replica region), plus backups in another location. Define RPO (data you can lose) and RTO (time to recover) and test them.

Backups

Automated daily backups and on-demand backups; PITR uses write-ahead logs or binary logs to restore to any second within the retention window, into a new instance (a clone).

Example

bash
# Add a read replica in another region for DR and reporting
gcloud sql instances create orders-db-replica-mumbai2 \
  --master-instance-name=orders-db \
  --region=asia-south2 \
  --tier=db-custom-4-16384

# Test failover in a staging environment
gcloud sql instances failover orders-db-staging

# Restore to a point in time as a new instance (clone)
gcloud sql instances clone orders-db orders-db-restore \
  --point-in-time='2026-12-05T10:15:00Z'

Follow-up questions interviewers ask

Try answering each one before you open it.

Does HA protect against a bad deployment that deletes data?

No. The standby receives the same writes synchronously, so the deletion is replicated too. Use backups and point-in-time recovery (restore into a clone and copy the data back), and protect against mistakes with migration reviews and least-privilege database users.