GitHub Repository: Shadab998/ds-2pc
This project implements the Two-Phase Commit (2PC) protocol to guarantee atomic distributed transactions for the CreateRoom operation across a microservices-based chat platform.
With 2PC, either all services commit, or all abort, ensuring strong consistency.
- Gateway Service
- Orchestrates:
- Phase 1: Voting
- Phase 2: Global Commit / Abort
Services that take part in the distributed transaction:
| Service | Description |
|---|---|
| Room Service | Stateful participant (SQLite) |
| Auth Service | Stateless participant |
| Presence Service | Stateless participant |
| Message Service | Stateless participant |
Everything needed to run 2PC is in the deployment/ directory.
No build step is required because all images are already on Docker Hub.
From inside deployment/:
docker-compose upThis launches:
- gateway (Coordinator)
- room
- auth
- presence
- message
- ui
When services are ready, you will see logs such as:
room-svc on :50052
presence-svc on :50053
message-svc on :50054
auth-svc on :50051
gateway-svc on :50055
A test client is provided to validate the distributed CreateRoom transaction.
Open a new terminal at the ds-2pc/deployment/tests, then run:
python test_client.py--- Sending CreateRoom request for test-room-1763... ---
--- SUCCESS: Gateway confirmed transaction COMMIT ---
You can also observe the docker terminal for detailed logs of Vote Decision by each node.
If any participant votes NO or times out:
--- ABORT: Gateway confirmed transaction ABORT {error-message} ---
- Full 2-Phase Commit protocol
- Atomic distributed room creation
- Coordinator-driven commit/abort flow
- Real RPC calls between microservices
- Fault-tolerant behavior (participant unavailable → abort)