You are designing the database tier for a globally distributed e-commerce platform on GCP. Transactions include order placement, inventory management, and payment processing. Compare Cloud Spanner and Cloud SQL for this use case, including cost, consistency guarantees, and migration complexity.
Quick Answer
Cloud Spanner provides global strong consistency with horizontal scaling for multi-region transactional workloads. Cloud SQL (PostgreSQL/MySQL) is cheaper for single-region deployments with read replicas. Choose Spanner when you need global writes with strong consistency; choose Cloud SQL when regional deployment suffices.
Detailed Answer
Cloud Spanner's Unique Value Proposition
Cloud Spanner is the only production database that offers global strong consistency (external consistency via TrueTime), horizontal read/write scaling, and 99.999% availability SLA in multi-region configurations. For an e-commerce platform processing orders across North America, Europe, and Asia simultaneously, Spanner ensures that inventory decrements in one region are immediately visible in all others—no eventual consistency windows where overselling could occur.
Cloud SQL for Regional Workloads
Cloud SQL provides managed PostgreSQL, MySQL, or SQL Server with automatic backups, HA failover (within a region), and read replicas. For a platform serving a single region, Cloud SQL is 5-10x cheaper than Spanner. A db-custom-8-32768 instance (~$500/month) handles thousands of TPS for typical OLTP workloads. Cross-region read replicas add read scaling but writes are always in the primary region, and replication lag means eventual consistency for reads in remote regions.
Cost Comparison at Scale
Spanner's minimum cost is 1 node (~$650/month per node) with a minimum of 1 node per region in multi-region configs. A typical production multi-region setup (nam-eur-asia1) requires at minimum 3 nodes (~$1,950/month) plus storage ($0.30/GB/month for multi-region). Cloud SQL HA in one region costs ~$500-1,000/month for equivalent compute. The cost gap narrows at scale: Spanner scales linearly with nodes while Cloud SQL hits vertical scaling limits, requiring application-level sharding.
Migration Complexity
Migrating to Spanner requires schema redesign. Spanner uses interleaved tables instead of foreign keys for parent-child relationships, primary keys must be designed to avoid hotspots (no auto-increment—use UUIDs or bit-reversed sequences), and there's no stored procedure support. The Harbourbridge tool automates schema conversion from PostgreSQL/MySQL but manual optimization is always needed. Spanner's PostgreSQL interface (PG dialect) reduces migration effort but doesn't support all PostgreSQL features.
Decision Framework for Production
Use Spanner when: multi-region strong consistency is required, write throughput exceeds single-node PostgreSQL limits, or the business cost of data inconsistency (overselling, double-charging) exceeds Spanner's infrastructure cost. Use Cloud SQL when: single-region deployment is acceptable, budget is constrained, team expertise is in PostgreSQL/MySQL, or the application uses features not available in Spanner (full-text search, stored procedures, PostGIS).