Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a distributed transaction?
A distributed transaction is a database transaction that involves multiple networked databases or systems. It ensures all parts of the transaction either commit or rollback together, keeping data consistent across all systems.
Click to reveal answer
beginner
What does 2PC stand for and what is its purpose?
2PC stands for Two-Phase Commit. It is a protocol used to ensure all participants in a distributed transaction agree to either commit or abort the transaction, maintaining data consistency.
Click to reveal answer
intermediate
Describe the two phases of the Two-Phase Commit protocol.
Phase 1: Prepare phase - The coordinator asks all participants if they can commit. Participants respond with 'yes' or 'no'. Phase 2: Commit phase - If all say 'yes', the coordinator tells everyone to commit. If any say 'no', the coordinator tells everyone to abort.
Click to reveal answer
intermediate
Why is the Two-Phase Commit protocol important in distributed systems?
It ensures atomicity across multiple systems, meaning either all parts of the transaction succeed or none do. This prevents data inconsistency when multiple databases are involved.
Click to reveal answer
advanced
What is a potential drawback of the Two-Phase Commit protocol?
2PC can cause blocking if the coordinator crashes after participants have voted 'yes' but before sending the commit command. Participants must wait, which can delay other operations.
Click to reveal answer
What does a distributed transaction ensure?
AAll parts commit or rollback together
BOnly one database is updated
CTransactions run faster
DData is duplicated
✗ Incorrect
Distributed transactions ensure all parts either commit or rollback together to keep data consistent.
In 2PC, what happens if any participant votes 'no' during the prepare phase?
AThe transaction commits anyway
BThe coordinator tells all to abort
CThe coordinator retries the prepare phase
DThe participant is removed
✗ Incorrect
If any participant votes 'no', the coordinator instructs all participants to abort the transaction.
Which phase of 2PC involves asking participants if they can commit?
APrepare phase
BValidation phase
CExecution phase
DCommit phase
✗ Incorrect
The prepare phase is when the coordinator asks participants if they can commit.
What problem can occur if the coordinator crashes during 2PC?
ATransaction is automatically aborted
BParticipants commit immediately
CParticipants block and wait
DNo effect on the transaction
✗ Incorrect
If the coordinator crashes after participants vote 'yes', they block waiting for the commit or abort command.
Which of the following is NOT a feature of distributed transactions?
ACoordination between databases
BData consistency
CAtomicity across multiple systems
DFaster single database queries
✗ Incorrect
Distributed transactions do not make single database queries faster; they focus on consistency across systems.
Explain how the Two-Phase Commit protocol works in a distributed transaction.
Think about the two steps that ensure all participants agree before finalizing.
You got /4 concepts.
What are the benefits and challenges of using distributed transactions with 2PC?
Consider both what 2PC solves and what problems it might cause.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Two-Phase Commit (2PC) protocol in distributed transactions?
easy
A. To ensure all participating systems agree to commit or abort a transaction
B. To speed up transaction processing by skipping checks
C. To allow partial commits in case of failures
D. To encrypt data during transaction processing
Solution
Step 1: Understand the role of 2PC in distributed systems
2PC coordinates multiple systems to either all commit or all abort a transaction, ensuring consistency.
Step 2: Analyze the options
Only To ensure all participating systems agree to commit or abort a transaction correctly describes 2PC's goal of agreement before finalizing changes.
Final Answer:
To ensure all participating systems agree to commit or abort a transaction -> Option A
Quick Check:
2PC ensures agreement = To ensure all participating systems agree to commit or abort a transaction [OK]
Hint: 2PC means all or nothing commit agreement [OK]
Common Mistakes:
Thinking 2PC speeds up transactions
Believing partial commits are allowed
Confusing 2PC with encryption
2. Which of the following is the correct sequence of phases in the Two-Phase Commit protocol?
easy
A. Commit phase followed by Prepare phase
B. Commit phase only
C. Abort phase followed by Prepare phase
D. Prepare phase followed by Commit phase
Solution
Step 1: Recall the 2PC phases
The protocol first asks participants to prepare (vote), then commits if all agree.
Step 2: Match phases to options
Prepare phase followed by Commit phase correctly lists Prepare phase first, then Commit phase.
Final Answer:
Prepare phase followed by Commit phase -> Option D
Quick Check:
2PC phases = Prepare then Commit [OK]
Hint: Prepare before commit in 2PC sequence [OK]
Common Mistakes:
Reversing the order of phases
Ignoring the Prepare phase
Thinking Commit happens alone
3. Consider a distributed transaction using 2PC with three participants: P1, P2, and P3. If P1 and P2 vote to commit but P3 votes to abort during the Prepare phase, what will be the final outcome?
medium
A. Only P1 and P2 commit, P3 aborts
B. All participants abort the transaction
C. All participants commit the transaction
D. Transaction is left in uncertain state
Solution
Step 1: Understand voting in 2PC Prepare phase
All participants must vote to commit for the transaction to proceed; any abort vote causes abort.
Step 2: Apply voting results
Since P3 votes to abort, the coordinator instructs all to abort to keep data consistent.
Final Answer:
All participants abort the transaction -> Option B
Quick Check:
Any abort vote = all abort [OK]
Hint: One abort vote cancels entire transaction [OK]
Common Mistakes:
Assuming partial commits are allowed
Thinking transaction stays uncertain
Ignoring abort votes
4. A distributed transaction using 2PC is stuck indefinitely in the Commit phase. What is the most likely cause of this problem?
medium
A. A participant failed to send its vote during the Prepare phase
B. All participants voted to abort during Prepare phase
C. The coordinator crashed after sending Commit messages but before receiving acknowledgments
D. The transaction was never started
Solution
Step 1: Identify causes of blocking in Commit phase
If the coordinator crashes after sending Commit but before acknowledgments, participants wait indefinitely.
Step 2: Analyze options
The coordinator crashed after sending Commit messages but before receiving acknowledgments matches this scenario; other options relate to earlier phases or no transaction.
Final Answer:
The coordinator crashed after sending Commit messages but before receiving acknowledgments -> Option C
Quick Check:
Coordinator crash during Commit causes blocking [OK]
Hint: Coordinator crash after commit message causes blocking [OK]
Common Mistakes:
Confusing Prepare phase failures with Commit phase blocking
Assuming abort votes cause commit blocking
Ignoring coordinator role
5. In a distributed system using 2PC, how can the protocol be improved to avoid the blocking problem caused by coordinator failure during the Commit phase?
hard
A. Use a Three-Phase Commit protocol that adds a pre-commit phase
B. Skip the Prepare phase to speed up commits
C. Allow participants to commit independently without coordinator
D. Increase the timeout for participant responses
Solution
Step 1: Understand blocking in 2PC
2PC can block if coordinator fails after sending commit but before acknowledgments.
Step 2: Identify protocol improvements
Three-Phase Commit adds a pre-commit phase to reduce blocking by ensuring participants can safely decide without coordinator.
Final Answer:
Use a Three-Phase Commit protocol that adds a pre-commit phase -> Option A
Quick Check:
3PC adds pre-commit to avoid blocking [OK]
Hint: 3PC adds pre-commit phase to prevent blocking [OK]