Skip to content

Repository files navigation

🚀 Sales Kafka - Orchestration Saga Pattern

Monorepo implementing the Saga Pattern (Orchestration) using Java, Spring Boot, Apache Kafka, PostgreSQL, MongoDB, and Docker.

Java Spring Boot Gradle Apache Kafka PostgreSQL MongoDB Docker Redpanda Console

📑 Table of Contents

🛠️ Technologies

  • Java 25
  • Spring Boot 4.1.0
  • Gradle 9.6
  • Apache Kafka
  • API REST
  • PostgreSQL
  • MongoDB
  • Docker
  • Redpanda Console

🏗️ Architecture

🎼 Orchestrated Saga Architecture

image

  • Order-Service: microservice responsible only for generating an initial request and receiving a notification. Here we have REST endpoints to start the process and retrieve event data. The database used will be MongoDB.
  • Orchestrator-Service: microservice responsible for orchestrating the entire Saga execution flow, it will know which microservice was executed and in which state, and which will be the next microservice to be sent, this microservice will also save the process from events. This service does not have a database.
  • Product-Validation-Service: microservice responsible for validating whether the product specified in the order exists and is valid. This microservice will store a product validation for an order ID. The database used will be PostgreSQL.
  • Payment-Service: microservice responsible for making a payment based on the unit values ​​and quantities informed in the order. This microservice will store the payment information for an order. The database used will be PostgreSQL.
  • Inventory-Service: microservice responsible for lowering the stock of products from an order. This microservice will store the download information of a product for an order ID. The database used will be PostgreSQL.

All services will go up through docker-compose.yml.

🗺️ Topic Mapping

Event Service Kafka Topic Type
PRODUCT_VALIDATION_SUCCESS order-service notify-ending consumer
FINISH_FAIL order-service start-saga producer
PRODUCT_VALIDATION_FAIL orchestrator orchestrator consumer
FINISH_FAIL orchestrator finish-success producer/consumer
PAYMENT_SUCCESS orchestrator finish-fail producer/consumer
PAYMENT_FAIL orchestrator notify-ending producer
PRODUCT_VALIDATION_FAIL product-validation-service product-validation-success consumer
INVENTORY_SUCCESS product-validation-service product-validation-fail consumer
INVENTORY_FAIL product-validation-service orchestrator producer
PAYMENT_FAIL payment-service payment-success consumer
FINISH_SUCCESS payment-service payment-fail consumer
payment-service orchestrator producer
inventory-service inventory-success consumer
inventory-service inventory-fail consumer
inventory-service orchestrator producer

▶️ Getting Started

☕ How to run

There are several ways to run:

🐳 Option 1 — Docker Compose

Running everything via docker-compose

⚙️ Option 2 — Build Script

Running everything through the automation script that i made available (build-bash.sh)

💻 Option 3 — Run Infrastructure Only

Running only the database and message broker (Kafka) services separately

☕ Option 4 — Run Services Manually

Running applications manually via CLI (java -jar or gradle bootRun or via IntelliJ)

📦 Requirements

To run the applications, you will need to have installed:

  • Docker
  • Java 25
  • Gradle 9.6

🔀 Choreography Version

👉 Check out the choreography-based implementation: https://github.com/Stephulz/sales-kafka-saga-choreographed

About

Monorepo of a project implementing orchestration saga pattern, using Kafka and Spring https://learn.microsoft.com/azure/architecture/patterns/saga

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages