In this lesson, you will learn why maintaining atomicity across multiple nodes requires significantly more overhead than a simple, single-node transaction.
The Single-Node Advantage
When you perform an UPDATE or INSERT on a single-node database, atomicity is relatively cheap. The database manages local locks and writes to a local transaction log. Once the data hits the disk (or memory buffer), the transaction is committed. The "cost" is effectively just the local I/O latency and the locking duration.
The Distributed Tax
When a transaction spans multiple nodes, you must use a protocol like Two-Phase Commit (2PC) to ensure that either all nodes commit or none do. This introduces several "hidden" costs:
- Network Round-Trips: In a single-node system, everything happens in-process. In a distributed system, the coordinator must send messages to every participant. If you have 5 shards involved in one transaction, the coordinator must wait for at least 10 network round-trips (a "prepare" phase and a "commit" phase) before completing.
- Extended Lock Duration: Because a distributed transaction cannot commit until every node has acknowledged the "prepare" phase, locks on all participating shards are held for the entire duration of these network round-trips. If the network is slow, those rows are locked for longer, drastically reducing your system's concurrency.
- Synchronous Log Flushing: To ensure durability in case of a crash, every participant must force a synchronous write to its own transaction log before voting "yes" in the prepare phase. This means your transaction speed is limited by the slowest disk across all participating nodes.
Visualizing the Latency
Compare the flow:
- Single-Node:
Application -> DB (Log Write) -> Commit - Distributed:
Application -> Coordinator -> (N x Network Delay) -> Participants (Log Writes) -> (N x Network Delay) -> Commit
As you increase the number of nodes involved, the probability of hitting a slow network link or a busy disk increases. Consequently, distributed atomicity turns a simple operation into a "bottleneck chain," where the speed of your transaction is only as fast as your slowest participant.
Key Takeaway: Distributed atomicity introduces a "tax" paid in extended lock duration and network round-trips, which makes system throughput strictly dependent on the latency of the slowest node in the cluster.