Skip to main content
← CONCEPTS / DISTRIBUTED SYSTEMS
An end-to-end domain learning journey

Google Percolator 2PC, Primary Locks
& Timestamp Oracle (TSO).

Percolator replaces a stateful 2PC coordinator with per-key MVCC data/lock/write columns, using the atomic commit of one chosen Primary Lock as the single commit point and resolving crashed transactions lazily.
Start the journey5 sections· Last modified Nov 28, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When implementing distributed Snapshot Isolation on a KV store, use Percolator's `data/lock/write` columns and lazy Primary-lock resolution.

TL;DR30-second simplified summary
▾

Prewrite checks for newer writes or active locks; Primary Commit atomically swaps lock for write(commit_ts) -> start_ts; expired Secondary locks resolve lazily via Primary status.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Two-Phase Commit (2PC)
Know why classic 2PC blocks participant locks if the central coordinator crashes after Phase 1.
MVCC Snapshot Isolation
Understand how reading at a fixed start_ts isolates readers from concurrent uncommitted writes.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

P · Problem & Why Classic 2PC Coordinators Block.

In traditional 2PC, Coordinator C asks Shard 1 and Shard 2 to PREPARE. Both write PREPARED to disk and hold row locks.

If Coordinator C crashes before sending COMMIT, Shard 1 and Shard 2 cannot safely commit or abort on their own—they are stuck holding locks indefinitely, blocking every other transaction touching those keys!

Coordinator Resilience

Stateful 2PC Coordinator (Blocks on Crash) vs. Percolator Primary Lock

Before · Classic Coordinator 2PC
  • Coordinator crash blocks locks
  • Participants stuck in-doubt
  • Separate central TX log
After · Percolator Client 2PC
  • Primary Key is single commit point
  • Lazy roll-forward / rollback
  • Zero central TX coordinator
02
L4 · FUNDAMENTALS

R · Representation: `data`, `lock`, and `write` MVCC Columns.

Every key in Percolator has three logical column families indexed by timestamp:

(1) data @ start_ts: holds the actual uncommitted/committed value; (2) lock @ start_ts: holds {primary_key, lock_type, ttl} while a transaction is in flight; (3) write @ commit_ts: holds a pointer -> start_ts once committed (making data @ start_ts visible to reads with read_ts >= commit_ts).

Percolator MVCC Columns

Three RocksDB Column Families Per Key

03
L5 · APPLIED DESIGN

I · Invariant: Prewrite Conflict Checks & Atomic Primary Commit.

During Prewrite(start_ts), each involved shard checks two conditions in a single local Raft transaction: (1) Is there any write at ts >= start_ts? (Write-write conflict -> Abort!); (2) Is there any existing lock on the key? (Contention -> Wait/Resolve/Abort!).

If both are clear, the shard writes data(start_ts) = val and lock(start_ts) = {primary: A, ttl}. Once all shards ack Prewrite, the client fetches commit_ts from TSO and sends Commit(start_ts, commit_ts) to Primary Key A alone.

2PC Execution

TSO(start_ts) -> Prewrite A & B -> TSO(commit_ts) -> Commit Primary A -> Async B

ClientTSOShard A (Primary)Shard B (Secondary)1. Get start_ts = 102. Prewrite A (lock + data @ 10)3. Prewrite B (lock -> A @ 10)4. Commit Primary A (ts=15) -> OK!
04
L5 · APPLIED DESIGN

M · Mechanics at Scale: Lazy Lock Resolution & TSO Batching.

What if a client commits Primary A (write @ 15), then crashes before committing Secondary B (lock @ 10)?

When Reader R later scans Key B at read_ts = 20, it sees lock @ 10 (with primary: A). If the lock's TTL has expired, Reader R checks Key A: (1) If Key A has write(commit_ts=15) -> 10, the transaction committed—so Reader R rolls forward Key B by writing write(15) -> 10 and deleting lock @ 10! (2) If Key A still has lock @ 10 or a rollback record, Reader R rolls back both Key A and Key B.

Lazy Lock Resolution

Reader Sees Expired Lock on B -> Inspect Primary A -> Roll Forward or Rollback

read primary ptrA has write(commit_ts)A locked / rolled backExpired Lock on BInspect Primary ARoll Forward(Committed)Rollback (Aborted)
Engineering Decision Framework
Problem
How to run distributed ACID Snapshot Isolation across sharded KV without central coordinator stalls.
Naive Solution
Use classic coordinator 2PC with per-transaction WAL logs on a central manager.
Why It Fails
Coordinator crashes leave locks stuck indefinitely and centralize I/O.
Alternatives
Classic 2PC vs. Percolator Primary-Lock 2PC vs. Spanner TrueTime.
Engineering Decision
Use Percolator Primary-Lock 2PC with a batched monotonic TSO and lazy TTL-based lock resolution.
Trade-Offs
Requires a single TSO service for global timestamps and extra Prewrite+Commit RTTs (unless 1-RTT Async Commit is enabled).
05
L6 · SCALE & TRADE-OFFS

E · Edge Cases, Assumptions & Limitations.

Standard Percolator provides Snapshot Isolation (SI), NOT full Serializable isolation—concurrent transactions reading disjoint keys and writing overlapping invariants can still experience Write Skew unless pessimistic SELECT FOR UPDATE locks are acquired.

Assumptions & Limitations: Relies on a highly available Raft-backed TSO (if TSO loses quorum, new transactions pause until TSO leader re-elects). Also, if a slow client stalls longer than its Primary lock TTL, a concurrent reader could roll back its Primary lock before it sends Commit—which is why commit_primary() MUST verify lock(start_ts) still exists before committing!

Percolator Components

Stateless Tx Client <-> Raft TSO + Region Raft Shards (Data/Lock/Write)

Stateless Tx ClientingressRaft-Backed TSOcontrolPrimary Shard(Raft)computeSecondary Shards(Raft)storagestart_ts / commit_tsprewrite + atomiccommitprewrite + asynccommit
Decision Exercise · Make the Call

Client 1 prewrites Primary A and Secondary B (start_ts=10, ttl=5s), then suffers a 10-second GC pause before calling commit_primary(A). Meanwhile, Client 2 cleans up the expired lock on A and rolls it back. What happens when Client 1 wakes up and calls commit_primary(A)?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

In Percolator, which single operation determines whether a distributed multi-shard transaction is committed or aborted?

Recommended Learning Flow