Distributed transactions and atomic commit 00:00:01 A ticket spans two accounts An account on the first shard holds two hundred fifty credits and another on the second holds a hundred seventy-five. A transfer should move twenty-five between them even though their local commit records belong to different participants. Both accounts must either commit the transfer or both must abort—no partial changes allowed to keep the system consistent. If one account commits and the other doesn’t, we’d lose 25 credits somewhere, breaking the total balance across the system. Both systems can exchange protocol messages, but they commit their own local data independently. The problem is agreement on one outcome for the transfer, not the ability to send a network packet between the two accounts. 00:00:42 Prepare without declaring completion The coordinator sends a prepare request to both account A and account B to check if they’re ready to commit the transfer. Each account records the intent to commit in durable storage before replying yes, ensuring it can follow through later. A participant that cannot prepare votes no. The transaction must abort, and prepared resources can be released when the global abort decision is learned. Internal log records may remain as recovery evidence. A participant voting yes makes a serious durable promise: it must retain enough information and resources to obey the later decision after a restart. Preparing consumes capacity even though a customer cannot yet call the transfer complete. 00:01:27 Make one durable decision With both yes votes, the coordinator writes COMMIT to durable storage before sending any decisions to the participants. After learning commit, shard one records a balance of two hundred twenty-five, and shard two records two hundred. Their total remains four hundred twenty-five credits. Even if a message is delayed, the same transaction ID lets the system retry safely without double-adding credits. The acknowledgements tell the coordinator which participants have learned the decision. Losing an acknowledgement after a successful commit does not change the recorded global decision and must not create a second transfer. 00:02:08 A prepared participant hears nothing Replay the network failure earlier: shard one voted yes but has not yet received the durable global decision. Shard two may already know it while the isolated participant does not. Even after a 30-second timeout, account A cannot assume abort—it must wait for the coordinator’s decision. Classic two-phase commit can block a prepared participant while the decision is unavailable. The resulting locks may delay work on the affected accounts without freezing every account in the database. A blocked prepared transaction can retain locks on the affected rows. Other independent transactions may continue. The hard part is that a participant cannot infer the global decision just from its own clock running out. 00:02:56 Separate agreement from cleanup The coordinator can recover using the durable commit record and re-notify account A once the network returns. A saga can expose intermediate business states and compensate under explicit rules. Two-phase commit instead coordinates one atomic decision, though readers still need suitable isolation to observe an intended consistent view. For this transfer, use atomic commit if the business requires it and both stores can sustain the coordination. If not, design an explicit in-transit state and a reconciliation contract instead of assuming independent commits will coincide. Choose two-phase commit only where the participants support the protocol and its blocking and latency are acceptable. Atomic agreement alone does not solve authorization, isolation, duplicate business intents or every customer-facing failure.