Calvin: deterministic distributed transactions without two-phase commit
How Calvin agrees on a global transaction order in 10 ms batches before taking any locks, then runs every replica deterministically with no two-phase commit.
Raft agrees on a log, entry by entry. Spanner takes locks, runs two-phase commit over Paxos and waits out clock uncertainty before releasing them. FoundationDB lets transactions run optimistically and has Resolvers abort the ones that conflict. Calvin does something else. It agrees on the order of transactions before anyone takes a lock, then has every node and every replica execute that order deterministically. Once the order is fixed, a transaction can’t be aborted by a crash or a deadlock, so there’s nothing left for two-phase commit to do.
The design is described in Calvin: Fast Distributed Transactions for Partitioned Database Systems by Alexander Thomson, Thaddeus Diamond, Shu-Chun Weng, Kun Ren, Philip Shao and Daniel J. Abadi (SIGMOD ’12), cited here as [Calvin]. Section numbers refer to it. Later context comes from the authors’ VLDB 2010 paper The Case for Determinism in Database Systems ([Det10]) and three posts by Daniel Abadi. Abadi is a Calvin author and was an advisor at FaunaDB, so read those posts as informed advocacy. Paragraphs marked My take are my own analysis.
The problem: locks held across network round trips
In 2012 most scalable stores had given up on transactions that span partitions. Dynamo, MongoDB, CouchDB and Cassandra had none. Bigtable allowed single-row transactions. VoltDB had full ACID but would “cease (or limit) concurrent transaction execution” for multi-partition work ([Calvin] §1).
The reason is two-phase commit. To keep isolation, “all of a transaction’s locks must be held for the full duration of this agreement protocol,” and 2PC takes several network round trips, often longer than the transaction’s actual work (§1.1). The paper names the cost: “We refer to the total duration that a transaction holds its locks—which includes the duration of any required commit protocol—as the transaction’s contention footprint.” Batching commit decisions saves CPU and network but “do[es] not ameliorate its contention cost.” Distributed locking also brings distributed deadlock, which is resolved by aborting transactions (§1.1).
Replication has a second problem. Serializability only promises equivalence to some serial order. Thread scheduling, caches, failures, network latency and deadlock resolution decide which one ([Det10] §1). So two replicas given identical inputs can still diverge, and “simply replicating transactional input is not generally sufficient” ([Calvin] §2).
My take: with hot keys, if at most 1/C transactions can hold a hot lock at once and each holds it for D seconds, throughput can’t exceed 1/(C·D) regardless of how many machines you add. The paper uses exactly this bound in §6.3. Shrinking D is the whole game.
The insight: two kinds of abort
Calvin’s §2 sorts the reasons a node might abort its share of a transaction into two kinds:
- Nondeterministic events, like a node crash. “There is no fundamental reason that a transaction must abort” because of these. If a replica is running the same plan in parallel, others can read from it, and the failed node finishes the work when it recovers.
- Deterministic logic, like “abort if stock would go below zero.” This needs no final vote. Each node waits for “a one-way message from each node that could potentially deterministically abort the transaction.”
If replicas agree on the input order and lock in that order, they all emulate the same serial execution. Then you only need to replicate inputs, in batches. The agreement happens “outside of transactional boundaries—that is, before they acquire locks” (§1.3).
Three layers
Calvin is a layer above any storage engine with a create/read/update/delete interface (§3). Every node runs one partition of three layers:
- The sequencer builds the global input order and replicates it.
- The scheduler locks records in that order and runs transactions on a pool of worker threads.
- Storage is a pluggable key-value engine.
Pulling concurrency control out of storage has a price. Calvin can’t use ARIES-style physiological logging or next-key locking against phantoms (§3). Logging isn’t a problem, because the state is “completely determined from the input” (§3.2). Range locking was left as future work.
The sequencer: 10 ms epochs
“Calvin divides time into 10-millisecond epochs during which every machine’s sequencer component collects transaction requests from clients” (§3.1). At the end of an epoch the batch is replicated. Then each scheduler in the replica gets the sequencer’s node ID, the epoch number and the transactions it takes part in. Every scheduler builds the same global order “by interleaving (in a deterministic, round-robin manner) all sequencers’ batches for that epoch.”
Replication comes in two modes (§3.1.1):
- Asynchronous. A master replica sequences everything and forwards batches. Latency is very low, but failover is complex: everyone must agree on the last valid batch and what it contained.
- Paxos-based synchronous. All replicas of a partition agree on each epoch’s batch. The implementation used ZooKeeper.
The paper’s Figure 2 measured this on 4 machines per replica, 40,000 transactions/s and 10% multipartition. Replicas were in one data center (about 1 ms ping) or spread across Virginia, Northern California and Ireland (100–170 ms ping). Reading the bars, average latency went from roughly 10 ms (async) to roughly 100 ms (Paxos, one data center) to roughly 500 ms (Paxos, three data centers). The text states the result that matters: “Total transactional throughput was not affected by changing Calvin’s replication mode.” Nobody holds a lock while Paxos runs.
Deterministic locking, and five phases with no vote
Each scheduler locks only records stored on its own node. Locking looks like strict two-phase locking with two extra rules (§3.2). Lock requests are made in the global order, by a single thread that requests every lock a transaction “will need in its lifetime.” And locks are granted strictly in request order. That’s why “all transactions are therefore required to declare their full read/write sets in advance.” Requesting all locks up front in one global order is “a well-known deadlock avoidance technique” ([Det10] §2), so there’s no deadlock detector and no deadlock aborts.
Once a transaction holds its locks, a worker runs it in five phases (§3.2):
- Analyze the read/write set. Nodes holding writes are active participants. Nodes holding only reads are passive.
- Read local records.
- Send local read results to every active participant. Passive nodes stop here.
- Collect remote read results.
- Execute the logic and apply only local writes. Remote writes are applied by the counterpart worker on the other node.
This is where two-phase commit goes away. A participant can’t crash its way out (a replica or a replay finishes the work), can’t deadlock, and any logic-based abort is computed from values every active participant already has. Abadi’s 2019 post It’s time to move on from two phase commit generalizes it: rewrite ABORT as an if every worker evaluates on the same values, and “the need for a commit protocol has been totally eliminated.”
Dependent transactions: reconnaissance first
Some transactions need to read data to learn what else they touch. Calvin calls these dependent transactions and handles them with Optimistic Lock Location Prediction (§3.2.1). First, a cheap, low-isolation, unreplicated, read-only “reconnaissance query” finds the read/write set. Then the real transaction is sequenced with that set. If the reads it depended on have changed by execution time, it’s “(deterministically) restarted.” Secondary indexes are rarely built on fields that change often, so restarts should be rare. TPC-C’s Payment transaction “never ha[s] to be restarted” (§3.2.1).
Disk: prefetch before locking
A normal database can reorder around a transaction stuck on disk. Calvin can’t, because the order is fixed, so anything that conflicts with the stalled transaction queues behind it (§4). The fix follows the paper’s guiding principle: “move as much as possible of the heavy lifting to earlier in the transaction processing pipeline, before locks are acquired.” The sequencer adds an artificial delay and asks storage to warm up cold records in the meantime. Latency is about the same, but “none of the disk latency adds to the transaction’s contention footprint” (§4).
In the experiments, throughput held at 10,000 transactions/s per machine as long as no more than 0.9% of transactions touched the local disk. Beyond that, the low-end disks ran out of random I/O. Getting at least 99% of prefetches done in time took a 40 ms delay. At low contention, the default batching delay, which “averages 5 ms,” was enough (§4, §4.1). Tracking which keys are in memory across every node was “not a scalable solution” and was left open (§4.2).
Checkpoints instead of REDO logs
Only the inputs are logged, so there’s no physical REDO log. Recovery is a checkpoint plus replay (§5). Calvin has three checkpoint modes. It can freeze one replica (which then falls behind). It can use a variant of the Zig-Zag algorithm that keeps “before” and “after” versions of each record around a virtual point of consistency, “a pre-specified point in the global serial order,” so nothing has to pause. Or, with multiversion storage, it can run a SELECT * to a file. In the paper’s measurement, the Zig-Zag variant caused “some reduction in total throughput” but didn’t increase lock contention or latency (§5). In the implementation, a crashed node restores its snapshot and replays, and the rest of its replica “is apt to slow or halt until recovery is complete” (§8).
The numbers
All experiments ran on EC2 High-CPU Extra-Large instances (§6):
- TPC-C, New Order only (Figure 4). With 10 warehouses per node and about 10% of orders crossing machines, Calvin reached about 5,000 transactions/s per node beyond 10 nodes, scaling linearly. That’s “nearly half a million TPC-C transactions per second on a 100 node cluster.” The record holder at the time ran 504,161 New Orders/s on much bigger hardware (§6.1).
- Scaling (Figure 5). Per-node throughput drops from one machine to two, because of the CPU cost of multipartition work. It keeps sagging as nodes are added, because of execution progress skew: one lagging node holds up everyone waiting for its reads (§6.2).
- High contention vs a 2PC model (Figure 6). On 100% multipartition workloads, Calvin slowed down about 5× to 7× at low contention, from 27,000 to about 5,000 or 4,000 transactions/s per machine. A simple model of a 2PC system, in which each distributed transaction holds its locks for about 8 ms (the two-phase commit latency alone), slowed down “significantly more” at high contention. The authors call the model “a strong lower bound” on a real 2PC system’s slowdown (§6.3).
Calvin vs Raft, Spanner and FoundationDB
- Raft. Raft is the replicated state machine idea: servers “compute identical copies of the same state” from a replicated log (Raft §2). Calvin applies it to a whole partitioned database. The agreed unit is an epoch batch of multi-partition transactions, and the state machine is a concurrent scheduler that still matches the serial order.
- Spanner. Spanner’s coordinator waits until TrueTime says the commit timestamp has passed (expected at least twice the clock uncertainty, overlapped with Paxos). Only then do participants apply and “release locks” (Spanner §4.2.1). Consensus and commit wait sit inside the contention footprint. In Calvin they sit before it. Abadi’s 2017 comparison, Spanner vs. Calvin, concedes that Spanner wins on read-only latency near partition leaders and supports interactive transactions. Spanner’s related-work section says Calvin-style systems don’t provide external consistency (§6). Abadi’s 2018 post, NewSQL database systems are failing to guarantee consistency, and I blame Spanner, argues that a single global log gives a natural order with no clock assumptions. The Calvin paper itself doesn’t claim external consistency, so treat this as a debate.
- FoundationDB. It also has a Sequencer, but it orders after execution. If any Resolver finds a read-write conflict, “the Proxy marks the transaction as aborted” (FDB §2.4.1). FDB keeps interactive transactions and accepts aborts. Calvin gives up interactivity in exchange for abort-free execution under heavy contention.
Fauna’s commercial protocol was “inspired by Calvin” but worked as a hybrid. It executed speculatively at a snapshot, put the transaction into a single Raft-ordered log, and had every replica re-check the reads deterministically, aborting and restarting if they had changed (Consistency without Clocks). According to the Fauna archive, Fauna announced in March 2025 that it was shutting down, and open-sourced its core.
Trade-offs
- You must know the read/write set in advance. No interactive transactions. Dependent transactions need reconnaissance and may restart. Nondeterministic calls like
time.now()must be pre-executed before sequencing (Abadi 2017). - Batching adds latency. Every transaction waits for its epoch and for replication, which means hundreds of milliseconds with cross-region Paxos, even though throughput holds.
- No reordering. A slow transaction or a slow machine holds up everything that depends on it. Disk stalls need predicted prefetch.
- The ordering path is tightly coupled. Every scheduler merges every sequencer’s batch for each epoch. Abadi’s 2018 post notes that one global consensus limits “the number of votes per second,” which is why batching matters.
- Failures are handled by replicas and replay, not aborts. Recovery can stall the affected replica (§8).
- Unbundling costs features, such as range locks and phantom protection (§3.2).
Patterns worth stealing
- Agree before you lock. Agreement still costs latency, but it no longer costs contention.
- Replicate causes, not effects. Deterministic execution turns a small input log into full replication and recovery.
- Turn system aborts into logic checks, so participants have nothing to vote on.
- Batch on a clock tick, so agreement is paid per batch and the order is simply (epoch, sequencer, position).
- Do slow work before the critical section: prefetch, reconnaissance reads.
- Checkpoint at a logical point in the order instead of pausing the world.
A design question for you
Design the purchase path for a global flash-sale ticketing platform. One event has 60,000 seats, and 2 million users in Mumbai, Frankfurt and Virginia try to buy in the first 90 seconds. Each purchase atomically touches a seat-inventory partition, the buyer’s wallet partition and a promo-code counter capped at 5,000 uses. You must never oversell, must lose no acknowledged purchase if a whole region fails, and must keep p99 under 600 ms at 50,000 attempts per second, with most attempts hitting the same 200 sections. “Best available seat” must work.
Would you use per-shard consensus with 2PC, optimistic validation, or deterministic ordering? Estimate each one’s contention footprint on a hot section. How do you handle “best available seat” when you don’t know the seat until you read? And where does the external payment call go, so that it neither breaks determinism nor holds locks?
Which of the three approaches would you bet on, and what would make you change your mind?
Sources
Primary source:
- Alexander Thomson, Thaddeus Diamond, Shu-Chun Weng, Kun Ren, Philip Shao and Daniel J. Abadi, Calvin: Fast Distributed Transactions for Partitioned Database Systems, SIGMOD ’12.
Background and later writing:
- Alexander Thomson and Daniel J. Abadi, The Case for Determinism in Database Systems, VLDB 2010.
- Daniel Abadi, Distributed consistency at scale: Spanner vs. Calvin, 2017.
- Daniel Abadi, NewSQL database systems are failing to guarantee consistency, and I blame Spanner, 2018.
- Daniel Abadi, It’s time to move on from two phase commit, 2019.
- Daniel Abadi, Matt Freels and Evan Weaver, Consistency without Clocks: The Fauna Distributed Transaction Protocol, 2018 (archived copy), and the Fauna blog archive.
For the comparisons:
- Diego Ongaro and John Ousterhout, In Search of an Understandable Consensus Algorithm; James C. Corbett et al., Spanner: Google’s Globally-Distributed Database; Jingyu Zhou et al., FoundationDB: A Distributed Unbundled Transactional Key Value Store.