atomic = all or nothing distributed transactions
- transaction - an operation
- distributed - one operation made up of many operations on multiple decoupled systems transactional = atomic = all or nothing
example: transactions to withdraw from bank A and save to bank B (either all are complete, or non complete), shouldn’t be a case where half is complete when reading.
Distributed transactions (atomic)
a way to determine should a transaction commit across all participants (ensuring all participants agree and are on the same page)
- 2-phase commit (strong atomicity)
- 2 steps
- prepare / vote
- commit
- all databases are atomic and when 1 database aborts, the entire transaction to all databases aborts
- Helps have ACID in distributed databases
- https://medium.com/geekculture/distributed-transactions-two-phase-commit-c82752d69324
- Acts as a single ACID commit
- problem: if coordinator dies before telling everyone, then all participants are idle
- 2 steps
- 3-phase commit (strong atomicity)
- 3 steps
- prepare / vote
- pre-commit
- commit
- solves problem of 2-phase commit, middle step of pre-commit, where coordinator will broadcast to all participants on the decision. so participants know safe to commit
- Adds a pre-commit phase to reduce blocking if the coordinator crashes
- participants can coordinate with each other to recognize theyve all reached pre-commit and can finish commit without coordinator
- This allows participants to use timeouts and their known protocol states to recover
- Adds a pre-commit phase to reduce blocking if the coordinator crashes
- 3 steps
- SAGA (eventual atomicity)
- Multiple commits sequentially (and rolling back each step upon failure)
- Simulates distributed transactions by having the programming model simulate consistency
- Need a state field in the db usually (to say it’s done)