▶ Cinematic fable · Watch on YouTube ▶ 影片版寓言 · 在 YouTube 观看

在京畿腹地的天工谷内,依山错落坐落着九座名震天下的工坊。

玄铁坊锻造百炼神兵与重型机括,青木坊刨削千步飞车与榫卯车厢,云锦坊纺织坚韧如金石的云丝软衬,玉琢坊雕刻灵枢轴承与符文玉牒。天工谷的技艺登峰造极,凡天下大宗器物的定制,无不需要九坊合力而成。

就拿一乘进贡御用的”天驷神车”来说,其工程浩大非凡:须由玄铁坊铸造三道减震悬簧与淬火轮轴,同时由青木坊拼接沉香车舆,再交由云锦坊缝入双层防箭蚕丝。

在早些年间,天工谷承接这等跨坊大单,靠的是各坊大工匠之间的“即席相商”。

每当京城客商手持巨额银票前来下定,负责接单的提调官便匆匆赶赴玄铁坊,把写着悬簧图样的木牌往案头一插,大喝一声:”占下天字一号地火铁砧!”随后,提调官派出一队脚力矫健的学徒,顶风冒雨穿过数里山道,分别奔向青木坊与云锦坊,去占下那里的沉香旋床与织锦机杼。

这套规矩推行了数十年,却几乎把整个天工谷逼入了绝境。

最大的灾难在于“两两相峙,动弹不得”。

有一年开春,边关急令赶造八百领铁叶明光铠,同时户部也下令督造一百艘破浪运粮船。铠甲需要玄铁坊先锻胸甲,再由云锦坊缝纫皮衬;运粮船需要云锦坊先织大帆,再由玄铁坊打造锚链。

造甲的学徒抢先占住了玄铁坊的熔炉,却发现云锦坊最好的织机已被运粮船占去;运粮船的管事死守着云锦坊不放,却在等玄铁坊空出锚链砧台。两家各不相让,铁砧冷了,织机空转,数百名工匠握着铁锤木梭,大眼瞪小眼地僵持在工坊前。这一等就是三天三夜,不仅两桩差事全部逾期,整个天工谷的通道也被堵得水泄不通。

更苦不堪言的,是各坊之间的“来回问询”。

哪怕没有遇上僵局,每当一件器物要跨坊组装,工匠们也必须小心翼翼地遵循所谓“两度质询”的旧例:各坊先把材料锁进秘匣,派出飞马信使往返数里山道,向提调官禀报”某坊已备妥,是否准行?”待提调官验齐九坊印信,再派人回送令箭:”准许开匣合龙!”

倘若哪位信使在山路上被暴雨滑断了腿,或者马匹失蹄跌入山涧,牵涉其中的数座工坊就只能死死锁住地火熔炉与旋床,谁也不敢动弹分毫。一旦其中一处因淬火爆裂而失手,所有参与的工坊更要把半成品的部件统统砸碎,数月心血化作飞灰。

九坊的大师们聚在谷中茶肆,皆是捶胸顿足:”天下之物,越是精巧,牵涉作坊便越广。如今我等大半时光不是耗在抡锤织锦,而是耗在锁死工台、苦等山道信使的马蹄声上!”

这般惨状,直到一位隐居少华山的算学宗师入主谷中掌纪司,才彻底迎来了颠覆。

宗师登上谷地中央高达九丈的通天钟楼,召集九坊主事,掷地有声地立下了一道石破天惊的新规:

“天下之事,因争序而僵,因不知彼此进而疑。从今往后,先定乾坤序,而后动一锤!”

宗师命人在钟楼设立了一座“太史录事阁”,并颁布了三道铁律:

其一,鸣钟封卷,统摄万机。 九坊门前彻底拆除了各自接单的柜台。天下所有无论大小、牵涉几坊的订单,一律直接送入通天钟楼。 每隔半个时辰,钟楼上的青铜巨钟便轰然鸣响一声(Epoch)。每鸣一声,录事官们便将这半个时辰内收到的所有契单收束成卷,用朱砂在卷轴上整整齐齐排下绝对不可更改的号筹:第一号、第二号、第三号……而后,录事阁以机关连珠飞索,将一模一样的“先序天工录”卷轴,同一瞬间分发至九座工坊的案头!

其二,按序执役,死结自解。 每一座工坊拿到卷轴后,各自展开。 玄铁坊的铁匠铺掌柜只看与玄铁有关的号筹,青木坊的木匠只看木作。但无论哪间工坊,都必须严格按照卷轴上的绝对序号分配铁砧、旋床与工匠! 若第七号器物与第九号器物同时需要天字一号地火铁砧,铁砧必须毫无争议地先归第七号使用,第九号工匠只能垂手肃立等待;而云锦坊里那台被争夺的织机,也同样一丝不差地先伺候第七号。 既然天下九坊皆遵奉同一份神圣次序,两家互卡咽喉的死锁之局,在落笔排号的那一弹指间,便已被彻底祓除于天地之外!

九坊主事起初惊叹,但随即提出了最为揪心的疑惑:”先生,排定先后容易,可这跨坊协同该当如何?玄铁坊打好了车轴,怎知青木坊今日车舆能否合龙?难道两坊之间不再派信使互相确认’是否准行’了么?”

宗师仰天长笑,道出了新法最为超凡入圣的精髓:

“其三,九坊默契,免除质询!”

“何谓天工录?天工录上写明第七号造天驷神车,那便意味着天工谷九座大坊每一位工匠的心中,皆已知晓第七号的存在! 玄铁坊的大师打完了车轴,无需向钟楼禀报,更无需派人向青木坊打听他们准备得如何。大师只需将通红的车轴淬入寒泉,装入密封铁篮,套在飞索滑轮之上,‘呼’的一声直接顺索滑向青木坊的院落! 青木坊的木匠按卷轴做到第七号时,只需伸手从滑索铁篮中抄起车轴,咔哒一声楔入车舆榫卯即可!”

一位老工匠颤声问道:”先生……当真无须再派信使来回问一句’你可备妥了、我可合龙了’?”

“一句也无须多问!”宗师目光如炬,”昔日之所以反复盘问,是因为谁也不知道对方何日开工、何时歇手、半途是否会反悔变卦;而如今,整座天工谷的生克次序早已在鸣钟那一刻被神明裁定! 只要各坊按章执役,结果便如日月运行般无可更改。既然知晓对方必定在此刻送来车轴,何须多此一举浪费口舌质询?”

自此以后,天工谷九座作坊内再无跨山飞奔的焦躁信使,更无横眉立目的抢工武斗。

半个时辰一鸣钟,钟声一响,万工齐动。铁砧起落如雷,飞梭穿行似电,无数机关部件顺着空中纵横交错的滑索精准穿梭。九座原本各自为政的工坊,仿佛化作了一尊庞大精密至极的千机浑天仪,吞吐如云,神采焕发。

天下客商莫不惊叹:昔日要耗费十天半月、推诿扯皮的跨坊神工,如今竟在连绵不绝的钟声之中,如行云流水般一气呵成!

—此时你大约已经认出:这套在事务执行之前先由独立层达成全局共识全序、各节点按序确定性获取本地锁、无需两阶段提交即可完成跨分区协调的非凡架构,正是分布式系统与新一代数据库领域中震撼学界的确定性分布式事务协议——Calvin。由耶鲁大学 Daniel Abadi 团队于 2012 年发表,它从根本上斩断了传统分布式两阶段提交(2PC)跨网络握手持锁的桎梏。

这是什么

Calvin 是由 Alexander Thomson、Daniel Abadi 等人于 2012 年在数据库顶级会议 ACM SIGMOD 上发表的里程碑式论文——《Calvin: Fast Distributed Transactions for Partitioned Database Systems》中提出的确定性分布式事务处理框架。

在传统的分布式关系型数据库与分布式事务系统(如经典两阶段提交 2PC、Google Spanner 或 Google Percolator)中,事务的执行流程通常是动态交错的:

  1. 客户端在各个分片节点上启动事务,边执行 SQL/逻辑边动态向存储引擎申请行锁;
  2. 当跨分片事务涉及的所有读写操作完成后,由协调者发起分布式两阶段提交(2PC:Prepare 与 Commit);
  3. 各分片在两阶段提交期间必须持续持有这些行锁,跨越广域网或数据中心的多轮网络往返(RTT),直至最终提交成功才释放锁。

传统机制在分布式环境下带来了巨大的性能开销:

  • 锁持有时间极长(Lock Contention & Long Hold Times):锁不仅覆盖本地 CPU 内存执行时间,还不得不覆盖不可控的网络延迟与共识等待;
  • 死锁频发(Deadlocks & Aborts):不同分片动态加锁顺序不一,极易陷入循环等待,导致事务频繁超时回滚,在高争用(High Contention)场景下吞吐量呈断崖式下跌。

Calvin 提出了一个颠覆性的架构思想:将事务的共识排序(Sequencing)与事务的并发控制执行(Scheduling / Execution)彻底解耦!在任何节点申请任何一把锁、触碰任何一条数据之前,先通过复制日志共识层确定全局唯一的事务执行全序。

Calvin 的核心体系由以下三层精密构成:

  1. 定序层(Sequencing Layer):
    • 客户端提交的事务请求首先由定序器(Sequencer)收集。
    • 定序器将事务划分为固定时间窗口(通常为 10 毫秒)的纪元(Epoch),并在纪元内为每个事务分配唯一的全局单调自增序号。
    • 定序层通过共识协议(如 Paxos 或 Raft)将定序后的事务列表复制到所有副本节点,确保所有存储节点收到完全一致、确定无疑的事务日志序列。
  2. 调度与并发控制层(Scheduling Layer & Deterministic Locking):
    • 存储分片节点拿到排好序的纪元事务批次后,由本地调度器负责分配锁。
    • 完全杜绝死锁的确定性加锁:调度器严格按照事务的全局序号依次申请读写锁。因为所有节点对所有事务的加锁顺序绝对一致,在数学上彻底消除了死锁的产生条件(循环等待被打破),因此 Calvin 不需要任何死锁检测、不需要死锁检测图、不需要超时打断!
  3. 执行层与无两阶段提交跨分区通信(Execution Layer & No 2PC):
    • 对于涉及多个分片的分布式事务,Calvin 将参与者划分为主动方(持有写集或执行逻辑的节点)与被动方(仅提供读集数据的节点)。
    • 被动方在本地按序读出所需记录后,直接通过点对点网络管道将数据打包发送给主动方;
    • 主动方收集齐所有远端依赖数据后,在本地确定性地执行状态机转换并落盘;
    • 彻底消除两阶段提交(Elimination of Distributed 2PC):既然事务在进入系统前就已经确立了全局不可逆的执行序列,且所有执行逻辑皆为确定性(Deterministic),那么每个节点都知道其他相关节点只要按照确定性逻辑推进,就必然会成功产出结果。因此,节点之间完全不需要来回发送 Prepare 和 Commit 确认帧!锁仅在本地内存读写完成的纳秒/微秒级别内持有,瞬间释放,绝不横跨分布式网络等待。

针对”事前难以预知读写集(Dynamic Read/Write Sets)”的事务(例如依据读出的主键再决定更新哪一行的二级索引查询),Calvin 引入了乐观侦察阶段(Optimistic Lock-free Reconnaissance Phase, OLR):先以无锁轻量方式预读一次推导出具体键集,再将确定性的键集送入定序器。若正式执行时发现预测失效,则由确定性逻辑触发统一重试。

为什么重要

Calvin 对现代分布式数据库理论与高并发系统架构产生了深远影响:

  1. 击碎分布式事务的”网络锁”枷锁:传统 2PC 的根本病灶在于将锁与跨节点网络延迟绑定。Calvin 通过”先定序、后执行”的确定性范式,将网络共识推移到了加锁之前,让加锁只存在于单机极速执行阶段,使得跨分片分布式事务的性能逼近单机本地事务。
  2. 极高争用与广域网多活(Geo-Replication)下的吞吐神话:在金融热点账户扣款、跨地域机房多活部署等极端场景下,传统事务系统因网络延迟拉长持锁时间导致冲突率暴增。Calvin 架构在面对高冲突负载时,依然能稳定保持极高吞吐,不会因反复死锁回滚而雪崩。
  3. 奠定现代确定性数据库的理论基石:Calvin 启发了诸多业界前沿的生产级系统与衍生系统,包括著名的全局多活数据库 FaunaDB(其核心共识与事务引擎正是 Calvin 的工业化实现),以及兼顾确定性与低延迟的混合系统如 SLOG、BOHM。理解 Calvin,是洞悉分布式系统如何超越经典两阶段提交藩篱的关键一步。

隐喻对应表

  • 天工谷内各自为政的九座名震工坊 → 分布式数据库的分片与存储节点(Partitions / Shards)
  • 各坊学徒跑腿占工台、互卡咽喉僵持三天三夜 → 传统分布式事务乱序加锁导致的分布式死锁(Distributed Deadlocks)
  • 开匣合龙前必须派快马往返通报九坊是否备妥 → 传统两阶段提交中的准备与确认网络往返(2PC Prepare & Commit RTT)
  • 暴雨阻断信使导致各坊熔炉死死冻结 → 协调者或网络分区引发的 2PC 阻塞持锁(2PC Lock Holding & Blocking)
  • 谷地中央高达九丈的通天钟楼与太史录事阁 → 独立的分布式共识定序层(Sequencer Layer / Consensus Log)
  • 半个时辰鸣钟一声收束所有契单(纪元划分) → 收集并切分事务批次的纪元时间窗口(Epoch Batching)
  • 录事阁排下不可更改的号筹并连珠分发卷轴 → 经由 Paxos/Raft 复制的全局严格单调递增事务全序(Replicated Global Total Order)
  • 各坊严格按照天工录卷轴序号分配铁砧与旋床 → 调度层按确定性全序申请锁、完全杜绝死锁(Deterministic Locking / Deadlock-Free Scheduler)
  • 玄铁坊打完车轴直接装入飞索铁篮顺滑至青木坊 → 参与节点读取数据后点对点单向投递至写节点(Point-to-Point Data Forwarding)
  • 青木坊取轴合龙无须向玄铁坊质询确认 → 确定性执行彻底消除分布式两阶段提交(Elimination of Distributed 2PC)
  • 绘制图样推算所需工坊材料的预备环节 → 预先推导事务读写集的乐观侦察阶段(Optimistic Reconnaissance Phase)

Deep in the heart of the imperial hinterland lies the Valley of Heavenly Craft, where nine world-renowned artisan guilds stand nestled along the mist-shrouded mountain terraces.

The Ironworks Ward forged hardened blades and massive clockwork gear trains; the Timber Ward shaped thousand-pace celestial chariots with intricate mortise-and-tenon framing; the Loom Ward spun damask silk linings as resilient as fine metal; and the Jade Ward polished frictionless mechanical bearings and rune-inscribed balance plates. The collective craftsmanship of the valley reached the pinnacle of mortal engineering. Whenever the imperial court or the grand trading leagues commissioned a monumental artifact, it invariably required the seamless cooperation of multiple guilds.

Consider, for example, the imperial commission for an armored “Celestial Steed Carriage.” The endeavor was gargantuan: it demanded three tempered leaf springs and oil-quenched steel axles from the Ironworks Ward, a fragrant sandalwood carriage frame assembled by the Timber Ward, and double-layered arrow-resistant raw silk upholstery stitched by the Loom Ward.

In earlier years, whenever the valley undertook such cross-guild undertakings, it relied entirely on impromptu, ad-hoc coordination among the master craftsmen.

Whenever an emissary arrived from the capital with a massive line of credit, the dispatch commissary would sprint to the Ironworks Ward, plunge an order stake into the foreman’s bench, and bellow: “Claim Forge Anvil No. 1 for Order A!” Next, the commissary dispatched a cohort of nimble-footed apprentices through miles of muddy mountain paths to the Timber Ward and Loom Ward, racing to claim the primary wood lathe and the master silk loom before anyone else could touch them.

This operational model governed the valley for decades, yet it eventually pushed the entire complex to the brink of collapse.

The primary disaster was cross-guild stalemate and gridlock.

One spring, the frontier command posted an urgent levy for eight hundred suits of iron lamellar armor, while the Ministry of Revenue simultaneously mandated one hundred river barges. The armor required the Ironworks Ward to forge breastplates before the Loom Ward could line them with hardened leather. The barges required the Loom Ward to weave heavy sails before the Ironworks could forge iron anchor chains.

The armor apprentices rushed in and claimed the great furnaces of the Ironworks, only to find the master loom in the Loom Ward already reserved for barge sails. Meanwhile, the barge overseers tenaciously held onto the looms, yet could not proceed because their apprentices were trapped waiting for an anvil in the Ironworks to free up. Neither faction would yield. Forge fires cooled, looms sat frozen in mid-stroke, and hundreds of master smiths and weavers stood glaring at one another with hammers and shuttles poised in vain. The standoff paralyzed the workshops for three days and three nights. Deadlines were blown, and all throughways across the valley ground to a dead halt.

Even more punishing than deadlocks was the agony of cross-guild round-trip verifications.

Even when an order avoided a deadlock, whenever components were ready for final assembly, the craftsmen were bound by the strict custom of “Two-Fold Interrogation.” Each guild locked its finished piece inside an iron strongbox and dispatched mounted couriers across the mountain trails to the central commissary: “Ward X is prepared; do we have clearance to commit?” Only after the commissary collected stamped seals from all participating guilds did he release the return tokens: “Clearance granted; unseal and combine!”

If a mounted courier slipped down a rain-soaked ravine or broke a leg along the mountain pass, the participating guilds remained paralyzed with tools suspended in midair, forbidden from moving an inch. And if a single casting cracked during final quench, all involved guilds were forced to smash their half-finished components into dust, flushing weeks of grueling labor down the drain.

The master craftsmen gathered at the valley teahouses, beating their chests in despair: “The more wondrous the artifact, the more guilds it must involve. Today, we spend less than a fraction of our hours swinging hammers or throwing shuttles; the rest is squandered guarding locked workbenches and straining our ears for the distant gallop of mountain couriers!”

The chronic dysfunction festered until a master logician and scholar from Mount Shaohua took command of the valley’s Registry Bureau.

Ascending the nine-story Celestial Bell Tower at the valley’s center, the master convened the masters of all nine guilds and proclaimed a revolutionary doctrine:

“All human affairs freeze in gridlock because men scramble for precedence; they stall in doubt because none know the progress of another. Henceforth: seal the universal sequence first, and only then strike the hammer!”

The master established the Grand Scribe’s Pavilion within the Bell Tower and instituted three immutable laws:

First, Chiming the Epoch and Total Ordering. The nine guilds dismantled their private intake desks. Every order, grand or humble, involving one guild or nine, had to be submitted directly to the Celestial Bell Tower. At the turn of every half-hour, the bronze bell atop the tower boomed across the valley (Epoch). With each chime, the scribes bundled all incoming orders received during that window and inscribed them onto a master scroll with absolute, immutable ordinal numbers: #1, #2, #3, and onward. Instantly, via a high-tension cableway network, identical copies of the “Preordained Celestial Chronicle” were zipped to the benches of all nine guilds simultaneously!

Second, Deterministic Execution and the Extinction of Deadlocks. Inside each workshop, the masters unrolled their copies of the scroll. The ironmaster examined only entries concerning steel; the woodcarver observed only timber. But regardless of the guild, every artisan was bound by law to allocate anvils, lathes, and master hands in the exact sequence of the roster numbers! If Order #7 and Order #9 both required Forge Anvil No. 1, the anvil was unconditionally assigned to Order #7 first. The craftsmen of Order #9 stood patiently with hands tucked into sleeves. Meanwhile, the contested loom in the Loom Ward was allocated to Order #7 with identical, unswerving precision. Because all nine guilds across the valley honored the exact same preordained sequence, cyclical deadlocks were mathematically annihilated before a single chisel touched wood or iron!

The guildmasters marveled at the orderliness, yet their deepest anxiety remained: “Master, establishing sequence is straightforward, but how do we coordinate across guilds? When the Ironworks finishes forging an axle, how does it know whether the Timber Ward’s carriage frame has succeeded? Must we not send couriers to inquire if they are ready to commit?”

The master logician laughed toward the heavens, unveiling the crowning jewel of the architecture:

“Third, Silent Harmony without Distributed Interrogation!”

“What is the Celestial Chronicle? The chronicle records that Order #7 is the Celestial Steed Carriage. That single truth means that every craftsman across all nine guilds already knows the complete destiny of Order #7! When the master smith finishes forging the carriage axle, he reports neither to the Bell Tower nor to the Timber Ward. He simply plunges the white-hot axle into cold mountain springs, secures it inside a sealed iron basket, hooks it to the aerial transit cable, and pulls the release lever—ziiiiip! The basket hurtles straight across the sky into the courtyard of the Timber Ward! When the timber artisan reaches Order #7 on his own copy of the chronicle, he reaches out his arm, lifts the axle from the basket, aligns the tenons, and hammers it home!”

An elderly artisan asked with a trembling voice: “Master… do we truly send no messenger to ask: ‘Are you prepared? Shall we finalize the contract?’”

“Not a single word!” the master replied, eyes shining with fierce conviction. “In former times, you interrogated one another because neither knew when the other would begin, when they would rest, or if they would abandon the work. Today, the destiny and ordering of the entire valley were ratified by heaven the moment the bell chimed! So long as each artisan executes his deterministic duty, the outcome unfolds as inevitably as the dawn. When you know with mathematical certainty that your brother artisan will deliver the axle at this very hour, what need is there to squander time whispering across the mountains?”

From that day forward, frantic couriers vanished from the mountain paths of the Valley of Heavenly Craft. Brawls over shared forges ceased forever.

Every half-hour, the bronze bell tolled, and ten thousand tools stirred in unison. Anvils rang like thunder, shuttles flew like streaks of silver light, and intricate components glided along high-tension aerial cables with breathtaking precision. The nine disparate guilds functioned as one colossal, harmonious celestial automaton, pulsing with boundless power.

Merchants from across the empire gasped in awe: complex multi-guild masterpieces that had previously dragged through weeks of bureaucratic wrangling now materialized in continuous, effortless triumph to the rhythmic tolling of the great bronze bell!

—By now you’ve probably recognized it: this revolutionary architecture of establishing global consensus on transaction ordering before locks are acquired, executing deterministic state transitions locally without distributed deadlocks, and eliminating the distributed commit protocol entirely, is the groundbreaking deterministic distributed transaction framework known as Calvin—introduced in 2012 by Daniel Abadi’s team at Yale University, which fundamentally shattered the latency and lock-contention shackles of classic Two-Phase Commit (2PC).

What it is

Calvin was introduced in 2012 by Alexander Thomson, Daniel Abadi, and their collaborators in their landmark ACM SIGMOD paper, “Calvin: Fast Distributed Transactions for Partitioned Database Systems.”

In conventional distributed relational database systems (such as those employing classical Two-Phase Commit 2PC, Google Spanner, or Google Percolator), transaction processing follows a dynamically interleaved execution model:

  1. Client transactions begin executing across partition nodes, dynamically requesting and acquiring row-level locks from storage engines as read/write operations occur.
  2. Once all operations finish, a designated coordinator initiates a distributed Two-Phase Commit (2PC: Prepare and Commit phases) across all participating shards.
  3. Shards must hold these locks continuously throughout the 2PC protocol, spanning multiple network round-trips (RTTs) across local networks or wide-area networks (WAN), until the transaction finally commits.

This conventional paradigm incurs catastrophic performance overheads in distributed environments:

  • Excessive Lock Duration (Lock Contention & Long Hold Times): Locks cover not just CPU computation time, but the unpredictable latency of network communication and distributed consensus.
  • Rampant Deadlocks and Aborts: Because transactions acquire locks dynamically in unpredictable orders across shards, distributed deadlocks are common. Resolving them requires aborting and retrying transactions, causing throughput to collapse under high contention.

Calvin introduced a paradigm shift: completely decouple the consensus/sequencing layer from execution and concurrency control. Before any transaction touches a single record or acquires a single lock, agree upon a globally unique, totally ordered transaction sequence via a replicated consensus log.

Calvin’s architecture consists of three core layers:

  1. Sequencing Layer (Sequencer):
    • Transactions submitted by clients are received by independent sequencer nodes.
    • Sequencers group transactions into discrete temporal batches known as epochs (typically 10 milliseconds). Within each epoch, each transaction is assigned a globally unique, monotonically increasing sequence number.
    • The sequencers run a consensus protocol (such as Paxos or Raft) to replicate the epoch batches across all replica sets, guaranteeing that every storage node receives an identical, immutable, and globally ordered transaction sequence log.
  2. Scheduling and Concurrency Control Layer (Deterministic Locking):
    • When a storage shard receives an epoch batch, its local deterministic scheduler allocates locks.
    • Deadlock-Free Deterministic Locking: The scheduler requests locks strictly in the ascending order of the global transaction sequence. Because every node requests locks in the exact same predefined sequence, circular wait conditions are mathematically impossible. Calvin requires no deadlock detection graphs, no wound-wait timeouts, and no transaction aborts due to lock contention!
  3. Execution Layer without Two-Phase Commit (No 2PC & Point-to-Point Messaging):
    • For distributed transactions spanning multiple partitions, Calvin analyzes read and write sets to classify nodes as active participants (nodes performing writes or executing logic) or passive participants (nodes merely providing read-only records).
    • Passive participants read requested records locally in sequence order and forward the data point-to-point directly to the active participants via network pipes.
    • Active participants assemble the remote read records, deterministically execute the transaction logic, and write modifications to storage.
    • Complete Elimination of Two-Phase Commit (Elimination of 2PC): Because the global order was finalized prior to execution and transaction logic is strictly deterministic, every participating node knows with certainty that all other participants will execute successfully. Nodes never exchange Prepare or Commit rounds! Locks are held solely for the microseconds required for local memory/disk computation, releasing immediately upon completion without waiting for WAN acknowledgments.

For transactions where read and write sets cannot be statically determined upfront (e.g., secondary index lookups or pointer chasing where write targets depend on read values), Calvin provides an Optimistic Lock-free Reconnaissance Phase (OLR): an initial lightweight, non-transactional read query inspects the database to predict key targets. The fully specified transaction is then submitted to the sequencer. If the underlying data mutated between reconnaissance and execution, the transaction aborts deterministically at the sequencer level and retries.

Why it matters

Calvin fundamentally reshaped distributed database theory and modern high-throughput transactional architectures:

  1. Eliminating the Network-Bound Lock Bottleneck: Classic 2PC inherently binds lock hold times to network latency. By ordering transactions before locking, Calvin isolates network consensus to the sequencing phase, allowing locks to be held strictly during local execution. Distributed transaction throughput approaches that of single-node engines.
  2. Resilience under Extreme Contention and Geo-Replication: In multi-region active-active deployments (where WAN latency exceeds 50–100ms) or hot-spot workloads (e.g., flash sales, financial ledgers), conventional 2PC throughput collapses due to lock queuing and abort cascades. Calvin maintains consistent, predictable high throughput regardless of network distance.
  3. Foundation of Modern NewSQL and Deterministic Engines: Calvin directly inspired production-grade cloud databases such as FaunaDB (whose transaction engine is a commercialized implementation of Calvin), as well as hybrid deterministic systems like SLOG and BOHM. Understanding Calvin is essential for mastering how modern distributed systems transcend the boundaries of classical Two-Phase Commit.

Metaphor mapping

  • Nine artisan guilds operating across the valley → Distributed database partitions and storage shards (Database Partitions / Shards)
  • Apprentices brawling over shared workbenches and halting work for days → Distributed deadlocks caused by unordered lock acquisition (Distributed Deadlocks)
  • Locking components inside strongboxes while couriers verify clearance across guilds → Classic Two-Phase Commit (2PC) holding locks across network round-trips (Distributed 2PC Lock Holding)
  • Mountain landslides stranding couriers and freezing workshops → 2PC coordinator failure or network latency causing blocking (2PC Blocking Problem)
  • Central Celestial Bell Tower and Grand Scribe’s Pavilion → Independent consensus and sequencing layer (Sequencer Layer / Consensus Log)
  • Chiming the bell every half-hour to seal all orders into a scroll → Batching transactions into discrete epochs (Epoch Batching)
  • Stamping identical sequential numbers and broadcasting scrolls via cableway → Replicating a globally unique, totally ordered sequence log via Paxos/Raft (Replicated Global Total Order)
  • Allocating anvils and lathes in strict scroll sequence without dispute → Deterministic locking acquiring locks in global sequence order without deadlocks (Deterministic Locking / Deadlock-Free Scheduler)
  • Sending forged axle directly via aerial basket to the Timber Ward → Active participants receiving read records point-to-point from passive participants (Point-to-Point Data Forwarding)
  • Timber Ward assembling the carriage without sending couriers to verify commit status → Deterministic execution completely eliminating Two-Phase Commit (Elimination of Distributed 2PC)
  • Sketching blueprints to deduce which workshops an order will touch → Optimistic reconnaissance phase predicting dynamic read/write sets (Optimistic Reconnaissance Phase)
Daily Fables每日寓言 2026-09-29