This diagram illustrates how the order lifecycle is managed using the Saga pattern across distributed microservices with Kafka as the event bus.
-
Microservices involved:
Order Service(Saga Coordinator)Payment ServiceRestaurant Service
-
Communication:
- Asynchronous, via Kafka topics
- Each service manages its own ACID-compliant transaction and publishes events
| Service | Responsibility |
|---|---|
| Order Service | Initiates the order flow, coordinates the saga, manages order state transitions |
| Payment Service | Processes payments and sends response back |
| Restaurant Service | Confirms or rejects restaurant order preparation |
| Event | Transition |
|---|---|
| Order created | PENDING |
| Payment successful | PENDING → PAID |
| Restaurant approved | PAID → APPROVED |
| Payment/approval failed | → CANCELLING → CANCELLED |
| Topic Name | Description |
|---|---|
payment-request-topic |
Sent by Order Service to initiate payment |
payment-response-topic |
Sent by Payment Service with payment result |
restaurant-approval-request-topic |
Sent by Order Service to request approval |
restaurant-approval-response-topic |
Sent by Restaurant Service with approval result |
Order Servicecreates a new order → sets state toPENDING- Sends message to
payment-request-topic Payment Serviceprocesses the payment- On success → replies to
payment-response-topic→ order moves toPAID - On failure → saga is cancelled → moves to
CANCELLED
- On success → replies to
- After payment success, sends message to
restaurant-approval-request-topic Restaurant Serviceconfirms or rejects the order:- If approved → order moves to
APPROVED - If rejected → saga cancelled → order moves to
CANCELLED
- If approved → order moves to
Each service maintains ACID transactions in its own database. Consistency is maintained eventually, not through distributed transactions.