GCP Databases and BigQuery
From transactional SQL to serverless analytics
Cloud SQL, Spanner, Firestore, Bigtable and BigQuery are GCP's data tier. Relational OLTP to global SQL to serverless warehouse — each answers a different data question.
What you will learn
- Choose Cloud SQL vs Spanner vs Firestore vs Bigtable
- Explain BigQuery's serverless architecture
- Design global consistency with Spanner where needed
Cloud SQL is managed Postgres/MySQL; Spanner is globally distributed SQL with strong consistency; Firestore is a document NoSQL with real-time; Bigtable is wide-column for large-scale ops data; BigQuery is a serverless SQL warehouse.
What is this?
Google's data platforms: Cloud SQL (Postgres/MySQL/SQL Server managed, with read replicas and HA) for classic relational needs. Spanner: horizontally scaling, globally consistent SQL — one system that behaves like a database and scales like a NoSQL store. Firestore: serverless document DB with realtime listeners and atomic transactions. Bigtable: wide-column store for high-throughput time-series/ops data. BigQuery: serverless columnar data warehouse with SQL, storing data in columnar format with standard pay-per-query pricing.
Why do you need it?
- Cloud SQL de-risks the most common DB ops: backups, patches, HA.
- Spanner solves the 'I need global reads/writes with ACID' problem you can't build by hand.
- BigQuery gives warehouse capability with no servers and instant elasticity.
- Choosing the right one is a top-3 database interview question.
Mental model
A workshop with a bench, a global highway and a library
Cloud SQL, Spanner, BigQuery
The bench (Cloud SQL) is where one table's careful work happens. Spanner is the highway — many lanes (nodes) but one set of traffic laws (across regions). The library (BigQuery) is where every past record is indexed and queryable on demand.
How it works
- Cloud SQL runs managed Postgres/MySQL in your VPC with automated backups, replicas and HA (primary + standby).
- Spanner splits rows across nodes/paxos groups and uses TrueTime to give strong consistency globally.
- Firestore: document collections with indexes; scales automatically; billing per read/write/storage.
- Bigtable: rows keyed by a row key, sorted within tablets partitioning; good for very high write throughput.
- BigQuery: serverless multi-tenant columnar storage + Dremel engine; queries bill by data scanned.
Choosing a GCP data service.
In production
- A SaaS keeps user data in Cloud SQL with a read replica for reporting.
- A global booking app uses Spanner for inventory consistency across regions.
- A mobile gam3 stores player state in Firestore; a billing pipeline reads into BigQuery nightly for dashboards.
Best practices
- Start relational with Cloud SQL; reach for Spanner only when single-region SQL can't serve scale or global consistency.
- Give Firestore bounded queries and pay attention to index requirements.
- Bigtable: design the row key first (entity+time ordering), it determines read patterns.
- BigQuery: partition + cluster, use materialized views for hot metrics, and prefer public datasets to avoid cost surprises.
Common mistakes
- Choosing Spanner 'because it's cool' when Cloud SQL suffices; Spanner costs and complexity aren't free.
- BigQuery full-table scans on every dashboard — no partition/cluster filtering.
- Firestore reads without indexes → exceptions in prod.
- Running operational queries against the primary Cloud SQL instance instead of a replica.
Common issues
Cloud SQL refuses connectionsPrivate IP + authorization rule missing, or instance down for maintenance
Authorize the connecting IP/subnets or use the private IP with VPC peering configured.
BigQuery query is slow/costs a lotNo partition filter, scanning the whole table
Add partition/column filtering and favor clustered/partitioned tables.
Firestore writes throttledHotspotting on a monotonically increasing field
Distribute keys; use a hash/sharding prefix to spread writes.
Debugging tips
- Cloud SQL slow: slow-query log + EXPLAIN before scaling the machine.
- BigQuery cost: look at bytesProcessed per query in the query history UI.
- Firestore errors: read the index errors; add the suggested composite indexes.
- Spanner latency: examine key distribution (hotspotting) and transaction isolation.
Interview checkpoint
Quick quiz
Which GCP service gives globally consistent SQL at scale?