What if your money transfer got lost halfway because systems didn't talk to each other?
Why Distributed transactions and 2PC in DBMS Theory? - Purpose & Use Cases
Imagine you are managing money transfers between two different bank accounts located in separate systems. You try to update both accounts manually, one after the other, without any coordination.
This manual approach is risky because if one update succeeds and the other fails, the money could disappear or be duplicated. It's slow and error-prone since there's no guarantee both systems agree on the changes.
Distributed transactions with Two-Phase Commit (2PC) solve this by coordinating all systems to agree before making changes permanent. This ensures either all updates happen together or none do, keeping data consistent.
update accountA set balance = balance - 100; update accountB set balance = balance + 100;
begin transaction; prepare transaction; commit transaction if all agree; rollback if any fail;
It enables reliable and consistent updates across multiple systems, even when they are separate and independent.
When you transfer money between banks, distributed transactions ensure your money leaves one account and appears in the other without loss or duplication.
Manual updates across systems can cause errors and data loss.
Distributed transactions coordinate all systems to agree before committing.
Two-Phase Commit ensures all-or-nothing updates for consistency.