https://github.com/bruce-mig/saga-orchestration-axon
SAGA Orchestration Event Driven Architecture with Axon Framework
https://github.com/bruce-mig/saga-orchestration-axon
axon axon-framework saga saga-orchestration saga-pattern
Last synced: 3 months ago
JSON representation
SAGA Orchestration Event Driven Architecture with Axon Framework
- Host: GitHub
- URL: https://github.com/bruce-mig/saga-orchestration-axon
- Owner: bruce-mig
- Created: 2025-05-30T14:37:56.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-06-03T11:15:13.000Z (6 months ago)
- Last Synced: 2025-06-03T11:27:38.059Z (6 months ago)
- Topics: axon, axon-framework, saga, saga-orchestration, saga-pattern
- Language: Java
- Homepage:
- Size: 660 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SAGA Orchestration with Axon Framework
This repository demonstrates the implementation of the **SAGA Orchestration Design Pattern** in an Event-Driven Microservices Architecture using the Axon Framework. The system showcases coordinated business transactions (Sagas) spanning multiple microservices.
The system is resilient to failures by having compensatory transactions at each stage of the SAGA lifecycle.
## Architecture Overview
The platform consists of the following microservices:
- **Order Service**: Initiates and manages the saga lifecycle.
- **Payment Service**: Handles payment processing.
- **Shipment Service**: Manages shipment and delivery.
- **User Service**: Manages user information and authentication.
- **Notification Service**: Sends notifications about order status and updates.
- **Commons Package**: Contains shared classes, events, and utilities.
> **SAGA orchestration** is implemented in the Order Service, controlling the distributed transaction flow across all services.
### Architecture Diagram

## SAGA Process Flow
1. **Order Creation**: User places an order, which triggers the saga.
2. **Payment Processing**: Payment Service processes the payment.
3. **Shipment**: Upon successful payment, Shipment Service arranges delivery.
4. **Notification**: User receives status updates via Notification Service.
5. **Compensation**: If any step fails, the saga orchestrates compensating actions to maintain consistency.

## Getting Started
### Prerequisites
- Java 21+ (recommended)
- Maven or Gradle
- Axon Server (for event storage and messaging)
- Docker (for running services locally)
### Running the Services
Each microservice has its own separate database. Run the Axon server and the databases via Docker with the following command:
```bash
docker compose up -d
```
The Axon server is available on port `:8084`.
Each microservice is independently deployable. You can run them using your preferred IDE or via command-line tools.
```bash
mvn clean install
java -jar order-service/target/order-service.jar
java -jar payment-service/target/payment-service.jar
# ...repeat for other services
```
### Example: Placing an Order
To initiate a new order and start the saga, send a POST request to the Order Service:
**Endpoint:**
`POST http://localhost:9091/api/v1/orders`
**Request Body:**
```json
{
"productId": "123",
"userId": "user_2",
"addressId": "50",
"quantity": 10
}
```
This triggers the SAGA workflow, coordinating actions across payment, shipment, and notification services.
## Technologies Used
- **Java**
- **Spring Boot**
- **Axon Framework**
- **Event Sourcing & CQRS**
- **RESTful APIs**
- **Docker** (optional)
- **Maven/Gradle**
## Project Structure
```
order-service/
payment-service/
shipment-service/
user-service/
notification-service/
commons/
static/
```
## TODO
A comprehensive list of technical TODOs is maintained in [TODO.md](./TODO.md).
### High-level tasks
- [ ] Handle runtime errors more gracefully throughout the application
- [ ] Create Dockerfiles for the command and query services
- [ ] Implement a CI pipeline to build Docker images and publish them to a container registry
## Contributing
Contributions and suggestions are welcome! Please open issues or pull requests for improvements.
## License
This project is open source under the [MIT License](LICENSE).
---