ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/coordinator/tasks/task-9-3-three-phase-commit
TASK

Implementation

3PC adds PRE-COMMIT phase. If coordinator fails after PRE-COMMIT, participants can commit safely.

Sample Test Cases

Phase 1: PrepareTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1","n2","n3","n4"]}}
{"src":"c1","dest":"n1","body":{"type":"3pc_prepare","msg_id":2,"tx_id":"tx1","participants":["n2","n3","n4"],"operations":[{"key":"x","value":10}]}}
Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}
{"src":"n1","dest":"c1","body":{"type":"3pc_prepare_ok","in_reply_to":2,"msg_id":1,"tx_id":"tx1","votes":{"n2":"yes","n3":"yes","n4":"yes"}}}

Hints

Hint 1
Add PRE-COMMIT phase
Hint 2
PRE-COMMIT indicates intent to commit
Hint 3
Participants can proceed without coordinator
OVERVIEW

Theoretical Hub

Three-Phase Commit

3PC reduces blocking by adding PRE-COMMIT. Participants in PRE-COMMIT know decision was commit if coordinator fails.

Key Concepts

3PCnon-blockingpre-commit
main.py
python
Implement Three-Phase Commit - The Coordinator | Build Distributed Systems