When a news site or application grows from a single country to a global audience, its database has to do two things at once: guarantee strong consistency and keep scaling without downtime as traffic climbs. In traditional relational systems these goals usually pull against each other. This is exactly where Google's managed distributed database, Google Cloud Spanner, comes in.
Related reading: Database types guide · What Is PostgreSQL? · What Is OceanBase? · Cloud Database Services
What Is Google Cloud Spanner?
Cloud Spanner is a fully managed, horizontally scalable distributed relational database offered by Google Cloud. It aims to combine the SQL, schema, and ACID transaction support of classic relational databases with the global scalability of distributed systems. Products in this class are often grouped under the labels "NewSQL" or "distributed SQL."
Spanner is the cloud-delivered form of a distributed database technology Google used internally for years. It stands out by targeting strong consistency even for applications that span multiple regions and cannot fit into a single one. Because it is a managed service, Google handles most of the operational burden, including patching, replication, load balancing, and hardware failure recovery.
A Brief History: Where Spanner Came From
Spanner began as an internal system Google built to solve scaling problems in its own infrastructure. Google published an academic paper describing it, and Spanner became one of the most cited examples of the idea of a globally distributed, consistent database.
Over time Google turned the technology into a managed service that Google Cloud customers could use as well. It was later extended with additions such as a PostgreSQL-compatible interface, broadening its appeal to a wider developer audience. Spanner's architectural approach has also influenced many of the distributed SQL projects that emerged afterward.
Core Concepts and Architecture
A handful of core concepts explain why Spanner can be both scalable and consistent:
- Instance: The top-level unit that holds compute and storage resources. An instance can contain multiple databases.
- Node / Processing Units: The resource units that determine an instance's compute capacity. You size capacity by node count or by finer-grained processing units.
- Split: Spanner automatically divides tables into pieces by primary key ranges and distributes them across nodes. Splits subdivide as load grows.
- Replica: Data is kept in multiple replicas for durability and high availability; replicas can live in different regions.
- Configuration: Regional or multi-region configurations decide where data lives and how it is replicated.
To keep replicas consistent, Spanner uses a Paxos-based distributed consensus protocol. Each split has a replica group that replicates writes synchronously via Paxos. As long as a majority (quorum) is reachable, the system keeps operating even when a replica is unavailable.
TrueTime and Global Consistency
One of Spanner's most distinctive features is its approach to time, called TrueTime. In distributed systems the clocks of different servers can drift slightly, which makes it hard to establish a global order of operations.
Google data centers use GPS receivers and atomic clocks. Instead of reporting a single exact instant, TrueTime expresses time as an uncertainty interval: "now is somewhere between these two values." Spanner uses this to assign consistent commit timestamps and, by waiting out the uncertainty interval before a commit becomes visible (commit-wait), it secures a correct global ordering.
Strong Consistency and ACID Transactions
Many distributed NoSQL systems adopt an eventual consistency model in exchange for scale. Spanner takes a different path: it targets ACID guarantees not only for single-row operations but also for transactions that span many rows and tables.
- Atomicity: Either all changes in a transaction apply, or none of them do.
- Consistency: Transactions move the database from one valid state to another.
- Isolation: Concurrent transactions are isolated so they do not corrupt each other's view.
- Durability: A committed transaction is not lost, even during a failure.
In terms of the CAP theorem, Spanner prioritizes consistency and partition tolerance; in practice, Google's network infrastructure lets it target high availability as well. For read-only queries, it offers lock-free, timestamp-based read options that help read traffic scale.
Data Model and SQL Dialects
Spanner uses a relational data model: tables, columns, primary keys, secondary indexes, and foreign-key-style relationships. Queries are written in SQL. Spanner offers two SQL interfaces: Google's own dialect (GoogleSQL) and a PostgreSQL-compatible interface. The PostgreSQL interface gives teams a familiar surface close to existing PostgreSQL knowledge and tooling.
-- A simple table definition (GoogleSQL)
CREATE TABLE Customers (
CustomerId STRING(36) NOT NULL,
Name STRING(200),
Email STRING(320),
CreatedTs TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp=true),
) PRIMARY KEY (CustomerId);
-- Query
SELECT Name, Email
FROM Customers
WHERE CustomerId = @id;Spanner can apply schema changes (DDL) while the service is running and generally without downtime. That is an important convenience for production systems that must stay continuously available.
Interleaved Tables and Primary Key Design
Spanner offers interleaved tables to physically colocate related data. When you define a child table interleaved in its parent, related rows are stored together in the same split. This improves the performance of queries that read parent and child records together.
-- Orders table interleaved within Customers
CREATE TABLE Orders (
CustomerId STRING(36) NOT NULL,
OrderId STRING(36) NOT NULL,
Amount NUMERIC,
Status STRING(20),
) PRIMARY KEY (CustomerId, OrderId),
INTERLEAVE IN PARENT Customers ON DELETE CASCADE;Primary key choice directly affects performance in Spanner. Monotonically increasing keys, such as sequential counters or raw timestamps, can push all writes to the same split and create a "hotspot."
Scaling: Nodes and Processing Units
Spanner's promise is horizontal scaling without manual sharding. To add capacity you generally add nodes or processing units to the instance, and the system manages data distribution itself. Capacity is expressed in two units:
| Unit | Description |
|---|---|
| Processing Unit (PU) | The smallest capacity increment; enables fine-grained sizing for small workloads. |
| Node | One node corresponds to 1000 processing units. Large workloads scale by node count. |
| Split | A data piece formed automatically by key range; it subdivides and redistributes as load grows. |
| Auto-scaling | Options exist to adjust capacity automatically in response to load changes. |
High Availability and Configurations
There are two core availability configurations. In a regional configuration, data is replicated across multiple zones within a single region. In a multi-region configuration, data spans several geographic regions; this helps the service continue even if an entire region fails and can place reads geographically closer to users.
Google publishes service level agreements (SLAs) for Spanner in its official documentation, with higher availability targets stated for multi-region configurations. Because the configuration choice directly affects cost, latency, and durability, it should be decided based on business requirements.
Backup, Restore, and Change Streams
Spanner provides managed backup and restore capabilities. It also offers options to retain data version history for a defined window, supporting mechanisms such as point-in-time recovery that help you return to an earlier moment.
The change streams feature lets you track inserts, updates, and deletes on tables in near real time and forward them to other systems. This is useful for moving data into analytics warehouses, keeping search indexes fresh, or building event-driven architectures.
Where Spanner Is Used
Spanner shines in scenarios that need strong consistency and large-scale horizontal scaling at the same time:
- Financial services: Payments, wallets, and ledgers where exact consistency is essential.
- Retail and inventory: Cross-region stock and order management that prevents overselling.
- Gaming: Global player profiles, leaderboards, and state data.
- Global applications: Services spread across continents that want a single consistent data layer.
- Enterprise systems: Platforms seeking relational infrastructure ready for high availability and growth.
Spanner Compared With Traditional Databases
The table below roughly compares Spanner with classic single-node relational databases and typical distributed NoSQL systems. Details vary by product and configuration.
| Feature | Cloud Spanner | Classic RDBMS | Typical NoSQL |
|---|---|---|---|
| Data model | Relational (SQL) | Relational (SQL) | Key-value / document, etc. |
| Horizontal scaling | Built-in, automatic | Limited / manual | Usually strong |
| Transactions | Distributed ACID | ACID (single node) | Often limited |
| Consistency | Strong / external | Strong | Mostly eventual |
| Operations | Fully managed | Usually self-run | Varies |
For a comparative view, look at other distributed SQL systems such as OceanBase and at cloud database services in general.
Benefits and Trade-offs
Spanner is a powerful solution, but it is not the right tool for every workload. Weigh these trade-offs when deciding:
- Plus: It combines horizontal scaling without manual sharding with strong consistency.
- Plus: Its fully managed nature reduces operational burden; patching and replication are handled by Google.
- Plus: SQL and a familiar relational model make the learning curve relatively gentle.
- Caution: Cost can be high for small or infrequent workloads compared to a single-node database.
- Caution: Consider vendor lock-in to Google Cloud and the impact of primary key design on performance.
KEYDAL and Global Database Infrastructure
As a news site grows, the data layer becomes increasingly critical within the triangle of consistency, scaling, and availability. The right database choice matters, but so does the performance and operability of the infrastructure that hosts it. KEYDAL brings publishing software, hosting, and server infrastructure together for news sites, so publishers can focus on content while the infrastructure load stays with the team.