Skip to content

rahulreddy-001/2-phase-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Two Phase Commit with gRPC

This repository contains a small Go implementation of the Two Phase Commit (2PC) protocol using gRPC. The order service acts as the coordinator, while the store and delivery services act as participants.

Flow

  1. The order service sends prepare requests to reserve an item and a delivery agent.
  2. If both participants accept, the order service sends commit requests.
  3. The store and delivery services confirm the reservation against the same order ID.

Services

  • service/order: coordinator service and CLI helpers
  • service/store: store participant, runs on localhost:8088
  • service/delivery: delivery participant, runs on localhost:8087
  • protos: protobuf definitions and generated gRPC code

Run

The app expects PostgreSQL at:

postgres://postgres:postgres@localhost:5432/2pc?sslmode=disable

Start the participant services in separate terminals:

go run ./service/store
go run ./service/delivery

Prepare sample data and run the coordinator:

go run ./service/order populateDB
go run ./service/order

To clean the database:

go run ./service/order cleanDB

Terminal Execution

Terminal execution

About

This repository contains a small Go implementation of the Two Phase Commit (2PC) protocol using gRPC

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors