Distributed transactions explained in plain terms start with an ordinary problem: moving money from one account to another when the two accounts live in different databases. The central question is how to make sure the debit and the credit happen together, or not at all, when no single machine controls both, and the answer is a protocol that gets every database to agree before any of them commits.
A transaction that touches one database is a solved problem. A transaction that touches several is one of the hardest problems in distributed systems, because each database can fail independently, the network between them can drop messages, and a decision made on one machine may never reach another.
This article explains what distributed transactions are, the protocols that make them work, and why so many modern systems try to avoid them.
Key takeaways
- A distributed transaction spans several databases and must commit everywhere or nowhere.
- Two-phase commit is the classic protocol for coordinating it.
- Every participant must be able to prepare, vote, and then commit or roll back.
- Distributed transactions are slow because they wait for the slowest participant.
- Many systems avoid them with sagas, idempotency, or a single database per workflow.
What a distributed transaction is
A transaction is a group of operations that must succeed or fail together. In a single database, the engine guarantees this with a write-ahead log and locks, and the property is called atomicity. When the operations touch several databases, no single engine can provide the guarantee, so the databases must coordinate with each other.
The classic example is a bank transfer. The debit from one account and the credit to another must both happen, and a system that applies one without the other has created or destroyed money. If the two accounts sit in different databases, perhaps in different data centres, the transfer is a distributed transaction.
Ordering a product is the same shape: decrement the stock, charge the card, and create the shipment, and if any step fails, the others must be undone. Each step may belong to a different service with its own database, and the transaction is what ties them together into a single unit of work.
Two-phase commit, the workhorse
The standard protocol is two-phase commit. A coordinator, usually the service that started the transaction, asks every participating database to prepare. Each one checks that it can commit, writes the changes to its log, and votes yes or no. If all vote yes, the coordinator tells them all to commit; if any votes no, it tells them all to roll back.
The prepare step is the key. Once a database has voted yes, it has promised that it can commit, and it holds that promise until the coordinator tells it what to do. The promise is recorded durably, so that even if the database crashes and restarts, it remembers its vote and waits for the decision.
The cost is time. Every participant must wait for the slowest one, locks are held for the whole duration of the protocol, and a participant that hears nothing from the coordinator is stuck, unable to commit or roll back. Our guide to two-phase commit explains the protocol and its blocking problem in detail.
Isolation across databases
Atomicity is only half the problem. A distributed transaction must also be isolated, meaning that other transactions should not see its half-finished work. If one database commits while another is still preparing, a reader could see the debit without the credit, which is exactly the inconsistency the transaction was meant to prevent.
Databases handle this with locks held across the whole protocol. Each participant locks the rows it touches when it prepares, and holds those locks until the coordinator’s decision arrives, so no other transaction can read or change them in the meantime. The locks are what make the transaction appear atomic to the outside world.
The price of those locks is contention. A long-running distributed transaction can hold locks on several databases at once, blocking other work, and a slow participant can stall the whole system. This is why distributed transactions are usually kept short, and why teams measure their duration carefully. Our guide to serializability explains the strongest isolation guarantee, and our guide to MVCC explains the versioning technique that lets readers proceed without waiting for writers.

Distributed transactions compared with the alternatives
Because distributed transactions are expensive, the industry has developed several ways to avoid them. Sagas break a transaction into steps, each with a compensating action that undoes it, so a failure partway through is repaired by running the compensations backwards. Idempotent operations make retries safe, so a step that may have run can simply be run again.
The table below sets out the main contrasts.
| Aspect | Distributed transaction | Saga | Single database per workflow |
|---|---|---|---|
| Atomicity | Strong, all or nothing | Eventual, via compensation | Strong, within one database |
| Latency | High, waits for all participants | Low, steps run independently | Low, no coordination |
| Failure handling | Roll back everywhere | Run compensating actions | Local rollback only |
| Availability | Low, any failure blocks the group | High, steps retry freely | High, one database to keep up |
| Best for | Money movement, strict rules | Orders, bookings, long workflows | Work that fits in one store |
The practical result is that distributed transactions suit the small number of cases where strong atomicity is non-negotiable, while sagas suit long workflows and a single database suits everything that can be arranged to fit in one.
Where distributed transactions are used
Banking is the most demanding user. A transfer between accounts in different systems must be atomic, and the cost of getting it wrong is measured in real money, so banks accept the latency and the complexity of two-phase commit for the guarantee it provides.
Enterprise resource planning systems use them too. An order that touches inventory, billing, and shipping, each in its own database, is a distributed transaction in the classic sense, and the systems that run it were built in an era when two-phase commit was the standard answer.
Cloud databases offer them as a feature, with varying limits. Some support transactions across shards of a single database, others across regions, and all of them document the cost: higher latency, lower throughput, and stricter limits on transaction size and duration than single-database transactions.
Microservices, by contrast, mostly avoid them. A service that owns its own database cannot join a transaction with another service’s database without coupling the two, so microservice designs usually accept eventual consistency and repair inconsistencies with sagas instead.
Strengths and limits
The greatest strength of distributed transactions is the clarity of the guarantee. All or nothing, everywhere, is a promise that application developers can build on without thinking about partial failure, and for money and inventory that clarity is worth a great deal.
They are also a strength in regulated settings. Auditors understand transactions, the guarantees are well defined, and the failure modes are documented, which makes them easier to defend than a saga whose compensations must be reasoned about case by case.
The limits are real, though, and they are why the pattern is in retreat. Distributed transactions are slow, they hold locks across the network, they fail when any participant fails, and they couple services that would otherwise evolve independently. A system that uses them everywhere will be slower and more fragile than one that uses them only where they are truly needed.
Distributed transactions checklist
- Use a distributed transaction only where atomicity is non-negotiable.
- Keep transactions short to limit how long locks are held.
- Make every participant able to prepare, vote, and roll back durably.
- Handle a missing coordinator decision with a timeout and a recovery plan.
- Consider a saga when the workflow is long or spans many services.
- Consider one database per workflow when the data can be arranged that way.
- Test participant failure at every stage of the protocol.
- Monitor transaction duration; a rising average signals contention.
- Document what happens to a transaction that never gets a decision.
Frequently asked questions
What is a distributed transaction in simple terms?
It is a transaction whose operations span several databases, coordinated so that they all commit together or all roll back together.
How does two-phase commit work?
A coordinator asks every participant to prepare and vote, then tells them all to commit if every vote was yes, or to roll back if any vote was no.
Why are distributed transactions slow?
Because they wait for the slowest participant, hold locks across the network, and need several rounds of messages before anything commits.
What is a saga, and when is it better?
A saga breaks a transaction into steps with compensating actions, so a failure is repaired by undoing completed steps. It is better for long workflows that can tolerate temporary inconsistency.
Can a distributed transaction survive a participant crash?
Yes, if the participant recorded its vote durably before crashing; on recovery it waits for the coordinator’s decision and then commits or rolls back.
Do microservices use distributed transactions?
Rarely, because they couple services together. Most microservice designs use sagas and eventual consistency instead.
The bottom line
Distributed transactions explained in one line are this: several databases, one promise, all or nothing, whatever fails in between.
They are the strongest tool in the distributed systems toolbox, and also the heaviest, which is why wise teams use them sparingly and only where nothing weaker will do.
This article is general information about how distributed transactions work, not advice about designing transactions for a particular system.







