Skip to content
Shadab998Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

GitHub Repository: Shadab998/ds-2pc

Two-Phase Commit (2PC) – Distributed Chat System

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.


🏗️ Architecture Overview

Coordinator

  • Gateway Service
  • Orchestrates:
    • Phase 1: Voting
    • Phase 2: Global Commit / Abort

Participants

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

🚀 Running the System

Everything needed to run 2PC is in the deployment/ directory.
No build step is required because all images are already on Docker Hub.

1. Start all services

From inside deployment/:

docker-compose up

This 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

🧪 Testing 2PC

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

✔ Expected Output (Commit Case)

--- 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.

❌ Expected Output (Abort Case)

If any participant votes NO or times out:

--- ABORT: Gateway confirmed transaction ABORT {error-message} ---

🎯 What This Demonstrates

  • 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)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages