https://github.com/abbes-larbaoui/saga-pattern
Implimentation of SAGA Pattern
https://github.com/abbes-larbaoui/saga-pattern
design-patterns e-commerce event-driven-architecture java kafka microservice saga saga-pattern spring-boot
Last synced: about 2 months ago
JSON representation
Implimentation of SAGA Pattern
- Host: GitHub
- URL: https://github.com/abbes-larbaoui/saga-pattern
- Owner: abbes-larbaoui
- Created: 2024-06-02T16:46:13.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-03T08:08:04.000Z (over 1 year ago)
- Last Synced: 2025-06-23T00:38:58.309Z (4 months ago)
- Topics: design-patterns, e-commerce, event-driven-architecture, java, kafka, microservice, saga, saga-pattern, spring-boot
- Language: Java
- Homepage:
- Size: 59.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Distributed Order Management System
## Overview
This project implements a distributed order management system using the Saga pattern with microservices architecture. The system is composed of several services that handle different aspects of the order processing workflow, coordinated by an Orchestrator service. Kafka is used for event-driven communication between services. Kafka is running via Docker Compose.
## Technologies
- **Java 17**
- **Spring Boot 3.2.5**
- **Apache Kafka**
- **Docker Compose**## Services
The system includes the following services:
1. **Order Service**: Handles order creation and management.
2. **Payment Service**: Processes payments.
3. **Stock Service**: Manages inventory and stock reservations.
4. **Notification Service**: Sends notifications to customers.
5. **Orchestrator Service**: Coordinates the entire workflow, handling events and triggering compensating actions when necessary.## Architecture

### Saga Pattern
The Saga pattern is used to manage distributed transactions. Each service performs its local transaction and publishes an event. The Orchestrator handles these events and triggers the next step in the workflow or compensating actions in case of failures.
### Workflow
1. **Order Creation**: An order is created and an `ORDER_CREATED` event is sent.
2. **Payment Processing**: The Orchestrator listens for the `ORDER_CREATED` event and triggers a `PROCESS_PAYMENT` event.
3. **Stock Reservation**: Upon successful payment (`PAYMENT_COMPLETED` event), the Orchestrator triggers a `RESERVE_STOCK` event.
4. **Order Completion**: If stock reservation is successful (`STOCK_RESERVED` event), the Orchestrator sends an `ORDER_COMPLETED` event.
5. **Notifications**: The Notification Service sends notifications based on events.### Rollback Mechanism
If any step in the process fails (e.g., payment fails or stock reservation fails), the Orchestrator handles the rollback by sending compensating events to undo the previous actions.
### Timeout Management
A Timeout Manager is implemented to detect if an expected event does not arrive within a certain time frame, thereby triggering compensating actions to handle service unavailability.
## Prerequisites
- Java 17
- Docker & Docker Compose