0
0
Microservicessystem_design~20 mins

Two-phase commit (and why to avoid it) in Microservices - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Two-Phase Commit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of the two-phase commit protocol?
In a distributed system, what is the primary goal of using the two-phase commit protocol?
ATo allow nodes to commit independently without waiting for others.
BTo replicate data asynchronously across nodes for eventual consistency.
CTo ensure all participating nodes agree to commit or abort a transaction, maintaining atomicity.
DTo speed up transaction processing by parallelizing commits without coordination.
Attempts:
2 left
💡 Hint
Think about what atomicity means in transactions across multiple systems.
Architecture
intermediate
2:00remaining
Which component coordinates the two-phase commit process?
In a two-phase commit protocol, which component is responsible for coordinating the commit or abort decision among participants?
AThe coordinator node that sends prepare and commit/abort messages.
BEach participant independently decides when to commit.
CA load balancer that distributes requests evenly.
DA database replica that applies changes asynchronously.
Attempts:
2 left
💡 Hint
Consider who sends the 'prepare' message in the protocol.
scaling
advanced
2:00remaining
Why does two-phase commit limit scalability in microservices?
Which of the following best explains why two-phase commit can reduce scalability in microservice architectures?
AIt replicates data too quickly, overwhelming the network.
BIt allows services to commit independently, increasing inconsistency.
CIt uses asynchronous messaging that can lose data under load.
DIt requires all services to lock resources and wait, causing delays and blocking.
Attempts:
2 left
💡 Hint
Think about what happens when multiple services wait for each other.
tradeoff
advanced
2:00remaining
What is a major tradeoff when avoiding two-phase commit in distributed systems?
If a system avoids two-phase commit to improve performance, what is a common tradeoff it must accept?
AAccepting eventual consistency instead of strong atomic consistency.
BGuaranteeing immediate consistency but sacrificing availability.
CIncreasing the risk of deadlocks due to resource locking.
DReducing network latency by skipping message acknowledgments.
Attempts:
2 left
💡 Hint
Consider what consistency guarantees are relaxed when not using two-phase commit.
estimation
expert
3:00remaining
Estimate the impact of two-phase commit on transaction latency
Assume a distributed transaction involves 5 microservices communicating over a network with an average round-trip time of 50ms. Using two-phase commit, estimate the minimum additional latency introduced by the protocol before the transaction commits.
AAbout 50ms because only one message round-trip is needed.
BAt least 100ms due to prepare and commit phases involving multiple message exchanges.
CLess than 50ms since messages are sent in parallel.
DNo additional latency because commits happen instantly.
Attempts:
2 left
💡 Hint
Remember two-phase commit requires a prepare phase and a commit phase with message exchanges.