https://github.com/ckswls56/springboot-microservices-distributed-transaction-2pc
springboot 2 phase commit
https://github.com/ckswls56/springboot-microservices-distributed-transaction-2pc
2phasecommit msa springboot
Last synced: 5 months ago
JSON representation
springboot 2 phase commit
- Host: GitHub
- URL: https://github.com/ckswls56/springboot-microservices-distributed-transaction-2pc
- Owner: ckswls56
- License: mit
- Created: 2024-10-31T07:55:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-02T08:54:32.000Z (over 1 year ago)
- Last Synced: 2025-08-22T11:50:34.111Z (11 months ago)
- Topics: 2phasecommit, msa, springboot
- Language: Java
- Homepage:
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Distributed Transactions in Microservices Using 2-Phase Commit (2PC)
The services in this project are designed with microservice architecture for performing distributed transaction using 2-Phase Commit (2PC).
Each microservice exposes REST API interfaces that can be accessed through OpenAPI endpoint (/swagger-ui.html)
## Tech Stack
1. SpringBoot
2. Spring Data JPA
3. MySQL Database
4. RabbitMQ
## Pre-Requisites
1. RabbitMQ
- Start RabbitMQ in Docker with command `docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management` [Learn more](https://hub.docker.com/_/rabbitmq)
2. MySQL Database
- Start MySQL in Docker with command `docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag` [Learn more](https://hub.docker.com/_/mysql)
## Usage
1. Start `discovery-server`. Default port is 8761.
2. Start all microservices: `transaction-server`, `account-service`, `order-service`, `product-service`
3. Add some test data to `account-service` and `product-service`
4. Send order creation request to `order-service` for testing the flow.
## Architecture
In this microservice-based architecture design, `discovery-server` plays an important role for registering and retrieving the service instances from a centralize location.
The `transaction-server` is responsible for maintaining transaction status for multiple services for a given transactionId.
There are three applications: `order-service`, `account-service` and `product-service`.
The application `order-service` is communicating with `account-service` and `product-service`. All these applications are using MySQL database as a backend store.

## Distributed Transaction Flow
