How jcsalerno/microsservicos-padrao-saga-orquestrado works
Project Type and Purpose
• This is a distributed microservices system implementing the Saga orchestration pattern in Spring Boot. Its goal is to manage a business transaction (creating an order, validating products, processing payment, updating inventory) across five independent services, using Apache Kafka for async messaging and Docker for containerized deployment.
File Structure Analysis
• Top-level services:
• order-service (Spring Boot + MongoDB)
• orchestrator-service (Spring Boot, no DB, central saga orchestrator)
• product-validation-service (Spring Boot + PostgreSQL)
• payment-service (Spring Boot + PostgreSQL)
• inventory-service (Spring Boot + PostgreSQL)
• Each service contains:
• config (exception handlers, KafkaConfig)
• core (consumer/producer, DTOs, model/repository, service logic)
• application entrypoint (…Application.java)
• Dockerfile and Gradle wrapper
• Top-level orchestration: docker-compose.yml to spin up Kafka, databases, and all services.
Key Architectural Insights (from README)
• Central Orchestrator coordinates the saga, sending commands to each service in sequence via Kafka topics.
• Each service listens for its topic (consumer), executes its local transaction, then emits an “event” (producer) indicating SUCCESS or FAILURE.
• The orchestrator listens to those events to decide next steps or compensate on failures.
• Databases are per-service (MongoDB for orders; PostgreSQL instances for validation, payment, inventory).
a. Main Components
• Message Broker: Apache Kafka cluster (topics for commands/events)
• Databases: MongoDB, 3× PostgreSQL
• Docker Compose / Container Host layer (optional outer boundary)
b. Relationships & Interactions
• Order Service → publishes “StartSaga” event on Kafka topic
• Orchestrator Service → consumes “StartSaga”, issues “ValidateProduct” command → Kafka
• Product-Validation Service → consumes “ValidateProduct”, writes to Postgres, publishes “ProductValidated” → Kafka
• Orchestrator → consumes “ProductValidated”, issues “ProcessPayment” → Kafka
• Payment Service → consumes “ProcessPayment”, updates Postgres, emits “PaymentProcessed” → Kafka
• Orchestrator → … issues “UpdateInventory” → Kafka → Inventory Service → Postgres → emits “InventoryUpdated” → Kafka
• Orchestrator → emits “SagaCompleted” → consumed by Order Service → writes to MongoDB
• On any failure event, orchestrator issues compensating commands in reverse order.
c. Architectural Patterns
• Saga Orchestration pattern (central coordinator)
• Pub/Sub event-driven choreography under the hood but orchestrated by a dedicated service
• Database-per-service (bounded contexts)
• Containerized microservices via Docker Compose
d. Technologies & Frameworks
• Spring Boot (Java 17+) for services
• Apache Kafka (topics, producers, consumers)
• MongoDB (Order Service)
• PostgreSQL (Validation, Payment, Inventory)
• Docker & Docker Compose
Detailed Element Checklist
• Component labels: service name, technology, database