Three-phase commit
Three-phase commit (3PC) is a distributed agreement protocol that extends two-phase commit with an additional pre-commit round. The extra phase eliminates the blocking problem that occurs when a coordinator fails after participants vote to commit, by ensuring that participants can safely make progress on coordinator timeout. Meridian uses 3PC to coordinate atomic state transitions across sharded inference workers when adaptive routing rebinds requests mid-flight.
1. CanCommit phase
The coordinator asks every participant whether it can commit the proposed transaction. Each participant performs local validation, reserves the resources it would need to apply the change, and replies YES or NO. A single NO or a missed reply before the coordinator timeout aborts the round before any state moves forward.
2. PreCommit phase
If every participant voted yes, the coordinator broadcasts PRE_COMMIT. Participants durably log their intent to commit and acknowledge. This phase is what distinguishes 3PC from 2PC: once a participant has logged pre-commit, it knows the entire quorum was willing to commit, so it can finish the transaction unilaterally on coordinator failure instead of blocking indefinitely.
3. DoCommit phase
After collecting pre-commit acks, the coordinator sends DO_COMMIT. Participants apply the change, release reservations, and reply HAVE_COMMITTED. If a participant times out waiting for DO_COMMIT after it has already logged pre-commit, it commits on its own and the protocol still converges.
Example exchange
coordinator -> all : CAN_COMMIT(tx=42) participant_a -> coord : YES participant_b -> coord : YES participant_c -> coord : YES coordinator -> all : PRE_COMMIT(tx=42) participant_a -> coord : ACK participant_b -> coord : ACK participant_c -> coord : ACK coordinator -> all : DO_COMMIT(tx=42) participant_a -> coord : HAVE_COMMITTED participant_b -> coord : HAVE_COMMITTED participant_c -> coord : HAVE_COMMITTED