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.
- The order service sends prepare requests to reserve an item and a delivery agent.
- If both participants accept, the order service sends commit requests.
- The store and delivery services confirm the reservation against the same order ID.
service/order: coordinator service and CLI helpersservice/store: store participant, runs onlocalhost:8088service/delivery: delivery participant, runs onlocalhost:8087protos: protobuf definitions and generated gRPC code
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/deliveryPrepare sample data and run the coordinator:
go run ./service/order populateDB
go run ./service/orderTo clean the database:
go run ./service/order cleanDB