Spanner

A distributed, multi-version DB with strongly consistent ACID, schematised semi-relational data model.

First system to do external consistency aka linearisable (global ordering of transactions) at scale. This is implemented with standard database features (e.g. concurrency control, replication, 2-phase commit) as well as new features (e.g. auto-sharding, auto-rebalancing). This is made possible with the true-time API (leverages GPS & atomic clocks to provide a global time reference).

1. Transactions

Transactions that write use two-phase-locking: a transaction must acquire locks on all the data it wants to write before it can commit. This ensures that no other transactions can modify the data while the transaction is in progress.

Read-write transactions use read locks on all data that is read, acquired at the leader of the replication block. Here, the latest version is read, not based on the timestamp. Writes are buffered and acquire write locks at commit time. Timestamp is also assigned at commit time.

Read-only (latest) and snapshot read (at timestamp) are lock free.

2. Zones & Span Servers

The universe is divided into zones (data centers) and span servers are deployed in each zone. Each span server is responsible for a range of data, and the data is replicated across multiple span servers in different zones.

To enable replication, each span server has a leader and followers. The leader is responsible for coordinating writes and ensuring that they are replicated to the followers. The followers are responsible for serving reads and maintaining a copy of the data.

The leader has a lock table that tracks which transactions have acquired locks on which data.

3. Paxos

Paxos is a consensus algorithm that ensures that a group of nodes can agree on a single value, even in the presence of failures.

The leader recieves a client command, and proposes it to the followers. The followers respond with their votes, and if a majority of followers agree, the leader can commit the command. If the leader fails, a new leader is elected using Paxos.

If a transaction involves multiple Paxos groups, use transaction manager to coordinate the commit across all groups (2PC - two-phase commit).

4. Data Model

A directory is analagous to a bucket in BigTable. Its the smallest unit of data placement, and used to defined replicaiton. Its sharded into fragments if it grows too large.

Back to Home