QA
Intermediate LevelSystem Design & Architecture

What is the Two-Phase Commit (2PC) protocol and why does it suffer from blocking risks?

❓ Interview Prompt: Explain Two-Phase Commit (2PC), Phase 1 (Prepare) vs Phase 2 (Commit/Abort), Coordinator node SPOF, and blocking lock risks.

The Two-Phase Commit (2PC) protocol coordinates atomic transactions across multiple distributed database nodes:

2 Phases:

1
Phase 1 (Prepare): Coordinator asks all participant nodes if they can commit. Participants acquire locks and vote 'YES' or 'NO'.
2
Phase 2 (Commit/Abort): If all vote 'YES', Coordinator commands all nodes to 'COMMIT'. If any vote 'NO', Coordinator commands 'ABORT'.
β€’
⚠️ Blocking Risk: If the Coordinator crashes during Phase 2, participant nodes remain indefinitely blocked holding database locks!

Code Implementation Example

markdown
Two-Phase Commit (2PC) Protocol Flow:

[Coordinator] ──(Phase 1: Prepare?)──> [Node A] [Node B]
[Coordinator] <-- (Vote: YES/YES) ─── [Node A] [Node B]

[Coordinator] ──(Phase 2: Commit!)──> [Node A] [Node B]
πŸ’‘Two-Phase Commit (2PC) Prepare and Commit phases.
🎯 Interview Key Takeaway

Avoid 2PC for high-throughput microservices due to coordinator blocking risks; prefer eventual consistency Saga patterns.

#System Design#2PC#Two-Phase Commit#Distributed Transactions#Intermediate
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?