sample-spring-kafka-microservices
sample-spring-kafka-microservices copied to clipboard
Example microservices showing how to use Kafka and Kafka Streams with Spring Boot on the example of distributed transactions implementations with the SAGA pattern
Microservices with Spring Boot and Kafka Demo Project 
Articles
This repository is used as the example for the following articles:
- Distributed Transactions in Microservices with Kafka Streams and Spring Boot - how to implement distributed transaction based on the SAGA pattern with Spring Boot and Kafka Streams
-
Deep Dive into Saga Transactions with Kafka Streams and Spring Boot - how to implement distributed transaction based on the SAGA pattern with Spring Boot and fully Kafka Streams
KStream
andKTable
. You need to switch to the streams-full branch.
Description
There are three microservices:
order-service
- it sends Order
events to the Kafka topic and orchestrates the process of a distributed transaction
payment-service
- it performs local transaction on the customer account basing on the Order
price
stock-service
- it performs local transaction on the store basing on number of products in the Order
Here's the diagram with our architecture:
(1) order-service
send a new Order
-> status == NEW
(2) payment-service
and stock-service
receive Order
and handle it by performing a local transaction on the data
(3) payment-service
and stock-service
send a reponse Order
-> status == ACCEPT
or status == REJECT
(4) order-service
process incoming stream of orders from payment-service
and stock-service
, join them by Order
id and sends Order with a new status -> status == CONFIRMATION
or status == ROLLBACK
or status == REJECTED
(5) payment-service
and stock-service
receive Order
with a final status and "commit" or "rollback" a local transaction make before