recall

← recall

two-phase commit pattern

Coordinator asks every participant 'can you commit?' If all say yes, it tells them to commit; if any says no, it tells them to abort. Provides distributed atomicity at the cost of blocking on coordinator failure.

Coordinator asks every participant 'can you commit?' If all say yes, it tells them to commit; if any says no, it tells them to abort. Provides distributed atomicity at the cost of blocking on coordinator failure.

symptoms

  • distributed deadlocks during the prepare phase
  • transactions stuck in 'prepared' state after coordinator failure
  • throughput dominated by network round-trips

causes

  • need for ACID across multiple resource managers
  • no application-level fallback like saga

fixes

  • use 3PC or Paxos-Commit for non-blocking variant
  • prefer saga / outbox for cross-service workflows
  • co-locate transactions when possible to avoid 2PC entirely

you might say

  • 2PC
  • two-phase commit
  • prepare-then-commit

related

aliases: 2PC

topics: distributed-systems, databases, correctness

references: