Global and Wide-Column Databases on GCP: Cloud Spanner and Cloud Bigtable for Massive Scale
When Normal Databases Hit a Wall
- A single-node relational database can only scale up so far, and replicas scale reads, not writes
- Global apps need low-latency data in many regions and very high write rates
- Google built Spanner and Bigtable for these needs
Cloud Spanner
- A fully managed relational database with SQL, ACID transactions and horizontal scale
- Strong consistency globally, using Google's TrueTime clocks
- 99.99 percent (regional) to 99.999 percent (multi-region) availability SLA
- Scales by adding nodes or processing units. Data is split into splits automatically
- Supports GoogleSQL and PostgreSQL dialects, secondary indexes, change streams and graph and vector features
| Config | Use |
|---|---|
| Regional | Low latency in one region, survives zone failure |
| Dual-region / multi-region | Survives a region failure and serves global users. Higher cost and write latency |
bash
gcloud spanner instances create shop-spanner --config=regional-asia-south1 --description="Shop" --processing-units=100
gcloud spanner databases create orders-db --instance=shop-spanner --ddl='CREATE TABLE Customers (CustomerId INT64 NOT NULL, Name STRING(100)) PRIMARY KEY (CustomerId)'
gcloud spanner databases execute-sql orders-db --instance=shop-spanner --sql="SELECT COUNT(*) FROM Customers"
Spanner Design Tips
- Do not use a sequential primary key (like an auto-increment number). It creates hotspots. Use UUIDs, hashed or bit-reversed keys
- Interleave child tables in parents (for example Orders under Customers) to keep related rows together
- Use secondary indexes for lookups, and stale reads for cheaper, faster reads when slightly old data is fine
- Use Spanner Data Boost or federated queries for analytics without hurting production
Cloud Bigtable
- A fully managed wide-column NoSQL database (the technology behind Google Search and Maps)
- Very high throughput and low latency (single-digit milliseconds) at petabyte scale
- Data model: row key → column families → columns → cells with timestamps. Only the row key is indexed
- API compatible with HBase. No SQL joins or multi-row transactions
- Great for time series, IoT, ad tech, financial ticks, personalization
bash
gcloud bigtable instances create sensors --display-name="Sensors" --cluster-config=id=sensors-c1,zone=asia-south1-a,nodes=1
cbt -instance=sensors createtable readings
cbt -instance=sensors createfamily readings metrics
cbt -instance=sensors set readings device42#20261117T0900 metrics:temp=31.5
cbt -instance=sensors read readings prefix=device42#
Bigtable Design Tips
- Design the row key for your main query. Example:
deviceId#reverseTimestampto read newest first for one device - Avoid keys that start with a timestamp or sequential number (hotspots)
- Keep rows under a few MB, and use field promotion to put varied identifiers in the key
- Add clusters in other regions for replication, failover and read locality (app profiles route traffic)
Spanner vs Bigtable vs Others
| Spanner | Bigtable | Cloud SQL / AlloyDB | |
|---|---|---|---|
| Model | Relational (SQL) | Wide-column NoSQL | Relational (SQL) |
| Transactions | Global ACID | Single row | ACID (single primary) |
| Scale | Horizontal, global | Horizontal, petabytes | Vertical plus read replicas |
| Query style | SQL with joins | Row key and range scans | SQL with joins |
| Best for | Global OLTP, financial, inventory | Time series, IoT, huge key-value | Typical apps |
Practice
- Explain why an auto-increment key is bad in Spanner
- Design a Bigtable row key for 'latest 100 readings of one sensor'
- Choose a database for: global payments ledger, IoT telemetry at 1 million writes per second, small blog
- Create a 100 processing unit Spanner instance and run a query
Conclusion
Spanner gives a globally consistent relational database that scales horizontally. Bigtable gives massive-throughput NoSQL keyed by row. Design keys carefully to avoid hotspots, and use ordinary Cloud SQL when scale does not demand these.
Quick Summary: wall; Spanner; design; Bigtable; design; comparison.

