Distributed transactions
Inspired by Distributed Transactions Explained: 2 Phase Commit vs Saga Pattern
2 phase commit and saga patterns are the most common ways to solve this.
2 phase commit (2PC)
You can have a coordinator plan across services and commit all at once, but this is fragile if the coordinator dies.
All or nothing is hard on distributed systems, so you opt in for eventual consistency instead
Saga pattern
What's more common is the saga pattern.
You create business level undos. Once a transaction is committed, it is committed. But if one system fails, it can notify the other systems to undo somehow.
There is a temporary inconsistent state while it fixes itself but the systems are still available
The undo scenarios need to be really reliable too.
Sources
- Distributed Transactions Explained: 2 Phase Commit vs Saga Pattern inspired this note
Referenced by
- Database ShardingEstablished
Write-heavy: Too much data for 1 instance (storage or write per second) Read-heavy: when read replicas or caching are not enough. Global queries will be slower. Complexity to operate and keep data…