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.
- Once request has been placed then it will produce an event to
order-topicand 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-topicand it decides the final result based on the status from those events(if everything is okay then it produces
Note: You may think that since
order-result-topicand what if one of the other services sends
ACCEPTand other with
REJECTstatus. So, the
order-serviceconsumes that topic one by one and other services produces the event to that topic with
orderIdand this will guarantee that they will be in same partition always. You can check the implementation details.
inventory-servicewill complete the process based on the new event with new status from the
You can easily run the project using
Be sure that you have
docker available locally.