Saga Pattern Implementation using Spring Boot and Kafka


Note: userId and productId values can be 0-9, because, in the services, we are generating some dummy data.

  1. Once request has been placed then it will produce an event to order-topic.
  2. payment-service and inventory-service listen that order-topic and based on the order-status(also for other conditions, like checking stock and checking user money), they try to process that event and produce the results with new status to order-result-topic.
  3. order-service listens the order-result-topic and it decides the final result based on the status from those events(if everything is okay then it produces COMPLETED otherwise ROLLBACK).

Note: You may think that since order-service listens the order-result-topic and what if one of the other services sends ACCEPT and other with REJECT status. So, the order-service consumes that topic one by one and other services produces the event to that topic with orderId and this will guarantee that they will be in same partition always. You can check the implementation details.

  1. Then payment-service and inventory-service will complete the process based on the new event with new status from the order-service.

You can easily run the project using file. Be sure that you have mvn, java and docker available locally.


View Github