0
0
Microservicessystem_design~5 mins

Two-phase commit (and why to avoid it) in Microservices - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the Two-phase commit protocol?
Two-phase commit is a method used to ensure all parts of a distributed system agree to commit a transaction or all abort, maintaining data consistency.
Click to reveal answer
beginner
What are the two phases in the Two-phase commit protocol?
Phase 1: Prepare phase where all participants vote to commit or abort. Phase 2: Commit phase where the coordinator tells all participants to commit or abort based on votes.
Click to reveal answer
intermediate
Why is Two-phase commit considered a blocking protocol?
Because if the coordinator crashes after participants vote to commit but before sending the final decision, participants wait indefinitely, blocking resources.
Click to reveal answer
intermediate
Name one major drawback of using Two-phase commit in microservices.
It reduces system availability and scalability because services must lock resources and wait for the coordinator, causing delays and potential deadlocks.
Click to reveal answer
intermediate
What are some alternatives to Two-phase commit in microservices?
Alternatives include eventual consistency patterns like Saga, event-driven architectures, and compensating transactions to avoid blocking and improve scalability.
Click to reveal answer
What does the coordinator do in the first phase of Two-phase commit?
AAsks participants if they can commit
BCommits the transaction immediately
CAborts the transaction
DSends the final commit decision
Why can Two-phase commit cause system blocking?
ABecause it commits transactions too fast
BBecause participants wait for the coordinator's final decision
CBecause it does not use locks
DBecause it only works on a single machine
Which of the following is NOT a reason to avoid Two-phase commit in microservices?
AIt improves scalability
BIt reduces availability
CIt can cause deadlocks
DIt increases latency
What is a common alternative to Two-phase commit for distributed transactions?
ANo transaction management
BSingle-phase commit
CManual commit
DSaga pattern
In Two-phase commit, what happens if a participant votes to abort during the prepare phase?
AThe coordinator ignores the vote
BThe transaction commits anyway
CThe coordinator tells all to abort
DThe participant retries automatically
Explain the Two-phase commit protocol and why it can cause problems in microservices.
Think about how waiting for a coordinator affects distributed services.
You got /4 concepts.
    Describe alternatives to Two-phase commit and how they improve distributed transaction handling in microservices.
    Consider patterns that avoid locking and blocking.
    You got /4 concepts.