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.
- Java 17
- Spring Boot 3.2.5
- Apache Kafka
- Docker Compose
The system includes the following services:
- Order Service: Handles order creation and management.
- Payment Service: Processes payments.
- Stock Service: Manages inventory and stock reservations.
- Notification Service: Sends notifications to customers.
- Orchestrator Service: Coordinates the entire workflow, handling events and triggering compensating actions when necessary.
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.
- Order Creation: An order is created and an
ORDER_CREATED
event is sent. - Payment Processing: The Orchestrator listens for the
ORDER_CREATED
event and triggers aPROCESS_PAYMENT
event. - Stock Reservation: Upon successful payment (
PAYMENT_COMPLETED
event), the Orchestrator triggers aRESERVE_STOCK
event. - Order Completion: If stock reservation is successful (
STOCK_RESERVED
event), the Orchestrator sends anORDER_COMPLETED
event. - Notifications: The Notification Service sends notifications based on events.
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.
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.
- Java 17
- Docker & Docker Compose