Cloud SQL vs. Cloud Spanner: Navigating the Relational Landscape on GCP

In the modern cloud era, “one size fits all” no longer applies to databases. For architects building on Google Cloud Platform, the choice between Cloud SQL and Cloud Spanner is one of the most critical decisions in the design phase. It’s a choice between the comfort of traditional relational systems and the boundary-breaking power of “NewSQL.”

Cloud SQL provides a fully managed home for your existing PostgreSQL, MySQL, and SQL Server workloads. It handles the “undifferentiated heavy lifting”—backups, patching, and failover—allowing you to scale vertically or via read replicas. It is the perfect fit for standard web applications, CMS platforms, and departmental tools.

However, what happens when your application outgrows a single region? What if your write volume exceeds what a single primary instance can handle? This is where Cloud Spanner enters the frame. Spanner is Google’s crown jewel of database engineering: a globally distributed, horizontally scalable relational database that provides strong consistency. Unlike traditional sharding, which introduces massive complexity, Spanner scales out transparently, making it the go-to for global finance, massive gaming backends, and high-velocity supply chain systems.

Study Guide: GCP Relational Database Services

The Analogy

Imagine you are running a Boutique Hotel (Cloud SQL). It’s highly efficient and offers premium service. If you get more guests, you can build a taller building (Vertical Scaling) or open a small gift shop next door (Read Replicas). But eventually, the foundation can only support so much height. Now, imagine a Global Hotel Franchise (Cloud Spanner). Every hotel in every city is perfectly synchronized. If a guest checks in at London, the Tokyo branch knows instantly. You can add 100 new hotels anywhere in the world, and they all act as one single, massive entity. That is the power of Spanner.

Detailed Explanation

Cloud SQL: A managed service for local/regional deployments. It supports Vertical Scaling (changing machine types) and Horizontal Read Scaling (Read Replicas). High Availability (HA) is achieved through a standby instance in a different Zone within the same Region.

Cloud Spanner: A “NewSQL” database. It combines the ACID compliance of a relational database with the horizontal scalability of NoSQL. It uses specialized hardware (Atomic Clocks) and the TrueTime API to ensure External Consistency across the globe. You don’t choose a machine size; you choose “Nodes” or “Processing Units.”

Real-World Scenarios

  • Scenario A: A regional e-commerce site using WordPress.
    Solution: Cloud SQL (MySQL). It’s cost-effective and perfectly compatible with the application code.
  • Scenario B: A global banking ledger requiring 99.999% availability and massive write throughput across three continents.
    Solution: Cloud Spanner. No single-region database can provide the global consistency and uptime required.

Comparison Table

Feature Cloud SQL Cloud Spanner
Engines MySQL, PostgreSQL, SQL Server Google Proprietary (SQL Interface)
Scaling Vertical (Read Replicas for Reads) Horizontal (Reads & Writes)
Consistency Strong (Regional) External Consistency (Global)
Availability 99.95% (HA) 99.999% (Multi-Regional)
Max Storage ~64 TB (varies by engine) Virtually Unlimited (PB scale)

Interview Questions & Answers

1. When should I move from Cloud SQL to Cloud Spanner?

Move to Spanner when your database size exceeds 10TB, your write throughput requires sharding in Cloud SQL, or you need global strong consistency.

2. How does Cloud SQL handle High Availability (HA)?

By using a primary and a standby instance in two different zones with synchronous replication at the storage level.

3. What is “TrueTime” in Cloud Spanner?

It’s a Google service using atomic clocks and GPS to provide tight clock synchronization, enabling Spanner to assign globally consistent timestamps to transactions.

4. Can Cloud SQL be multi-regional?

Not for writes. You can have Cross-Region Read Replicas, but the primary (write) instance is confined to a single region.

5. What is the minimum cost consideration for Spanner?

Spanner is significantly more expensive than Cloud SQL. It is billed per node (or 100 processing units) plus storage and networking.

6. Does Cloud Spanner support Foreign Keys and Joins?

Yes, it is a fully relational database and supports standard SQL, schemas, and ACID transactions.

7. How do you scale Cloud SQL for read-heavy workloads?

By adding Read Replicas (up to 10-15 depending on the engine) and offloading SELECT queries to them.

8. What is a “Read-Only Replica” in Spanner multi-region?

These are replicas that serve low-latency reads in distant regions without contributing to the voting quorum for writes.

9. Which service would you use for a legacy SQL Server migration?

Cloud SQL for SQL Server, as it provides the highest compatibility for existing T-SQL code.

10. What is the “Interleaving” feature in Spanner?

It’s a performance optimization where related rows from different tables are stored physically close together to reduce I/O during joins.

Golden Nuggets for the Interview

  • The “Sharding” Trap: If an interviewer asks how to scale Cloud SQL writes beyond one instance, the answer is “Manual Sharding” (complex) or “Migrate to Spanner” (architectural).
  • Availability: Remember the “Five Nines” (99.999%). Only Spanner Multi-Region offers this.
  • Postgres Compatibility: Spanner now has a PostgreSQL interface, making it easier for devs to migrate without learning a new dialect.
  • Horizontal vs. Vertical: Cloud SQL = Vertical (bigger box). Spanner = Horizontal (more boxes).

Architectural Decision Matrix

Application Cloud SQL Regional | Vertical | Managed Cloud Spanner Global | Horizontal | NewSQL SQL
Requirement:
Need standard MySQL/Postgres?
➜ Cloud SQL
Requirement:
Global writes > 10,000/sec?
➜ Cloud Spanner
Requirement:
Strict Budget?
➜ Cloud SQL
Service Ecosystem

Cloud SQL: Connects to App Engine, GKE, and Compute Engine via Cloud SQL Auth Proxy. Integrated with Looker for BI.

Spanner: Native integration with Dataflow for ETL and BigQuery for federated queries.

Performance & Scaling

Cloud SQL: Scale up to 96 vCPUs and 624GB RAM. Read throughput scales with replicas.

Spanner: Scale by adding nodes. 1 Node = ~10,000 reads/sec and ~2,000 writes/sec.

Cost Optimization

Cloud SQL: Use Sustained Use Discounts and Committed Use Discounts (CUDs). Stop instances during dev.

Spanner: Use Processing Units (PUs) for smaller workloads to start at 1/10th the cost of a full node.

Production Use Case

A global gaming company uses Cloud Spanner to store player profiles and inventory. This ensures that when a player buys an item in New York, their updated inventory is immediately visible when they log in from a mobile device in Singapore, preventing “double-spend” exploits. Meanwhile, they use Cloud SQL for their internal HR and employee payroll systems where regional data residency and lower costs are prioritized.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top