Q18: What is a distributed transaction, and why is it difficult?
A distributed transaction changes data across multiple independent participants. It is difficult because messages can be delayed, participants can fail, and a coordinator may lose contact after some participants have acted. Two-phase commit can provide atomic commitment but may block during failures and adds coordination overhead. Many service architectures instead use sagas with explicit compensating actions and eventual completion.
Key Takeaways
- Network failures make cross-service atomicity expensive.
- Use a saga when business workflows can be modeled as steps and compensations.