This project demonstrates the Saga Choreography pattern using Spring Boot and Kafka.
It simulates an Order workflow across multiple microservices with event-driven communication.
-
Order Service
- Accepts order requests from clients.
- Creates orders in
PENDINGstate. - Publishes
OrderCreatedEvent.
-
Inventory Service
- Consumes
OrderCreatedEvent. - Reserves product stock if available.
- Publishes:
InventoryReservedEvent(success)InventoryFailedEvent(failure)
- Consumes
-
Payment Service
- Consumes
InventoryReservedEvent. - Processes payment.
- Publishes:
PaymentCompletedEvent(success)PaymentFailedEvent(failure → triggers inventory release)
- Consumes
-
Shipping Service
- Consumes
PaymentCompletedEvent. - Prepares shipping.
- Publishes
OrderShippedEvent.
- Consumes
-
Order Service Compensation
- Consumes:
InventoryFailedEvent→ updates order asCANCELLEDPaymentFailedEvent→ updates order asCANCELLEDOrderShippedEvent→ updates order asCOMPLETED
- Consumes:
-
Client → Order Service
- API call:
POST /orders - Order status =
PENDING - Publishes OrderCreatedEvent
- API call:
-
OrderCreatedEvent → Inventory Service
- If stock available → Publishes InventoryReservedEvent
- If stock not available → Publishes InventoryFailedEvent
-
InventoryReservedEvent → Payment Service
- If payment successful → Publishes PaymentCompletedEvent
- If payment failed → Publishes PaymentFailedEvent
-
PaymentCompletedEvent → Shipping Service
- Shipping prepared → Publishes OrderShippedEvent
-
Failure Handling
InventoryFailedEvent→ Order Service updates status toCANCELLEDPaymentFailedEvent→ Order Service updates status toCANCELLEDand Inventory Service releases stock
-
Success Handling
OrderShippedEvent→ Order Service updates status toCOMPLETED
order-createdinventory-reservedinventory-failedpayment-completedpayment-failedorder-shipped
- Happy Path → Order moves through all services → status becomes
COMPLETED. - Failure Path → Any failure (Inventory or Payment) → order becomes
CANCELLED.
- Java 19
- Spring Boot 3
- Spring Kafka
- MySQL (Order DB)
- Docker / Docker Compose
- Apache Kafka & Zookeeper
- Start Kafka & Zookeeper using Docker.
- Run all microservices (
Order,Inventory,Payment,Shipping). - Place an order via Order Service API.
- Observe the choreographed events in Kafka topics.
Neelu Sahai