Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Kafka Microservices - SAGA Pattern with Kafka Streams

3-service microservices system implementing distributed SAGA orchestration using Kafka Streams.

Quick Start

# 1. Start Docker (Kafka + Zookeeper)
docker-compose up -d

# 2. Start all services
./start.sh

# 3. Create test order
curl -X POST http://localhost:8081/api/orders \
  -H "Content-Type: application.json" \
  -d '{
    "customerId": "CUST-001",
    "items": [
      {"productId": "PROD-001", "productName": "Laptop", "quantity": 2, "price": 1000.00}
    ]
  }'

Documentation

📖 ARCHITECTURE.md - Complete architecture, flow diagrams, and implementation details

📖 KAFKA-STREAMS-IMPLEMENTATION.md - Deep dive into Kafka Streams setup

Services

  • order-service (8081) - Order management + Kafka Streams orchestrator
  • payment-service (8082) - Payment processing
  • stock-service (8083) - Inventory management

Key Technology

  • Kafka Streams - KStream-KStream joins with 10-second time windows
  • SAGA Pattern - Distributed transaction coordination
  • Event-Driven - Kafka topics for inter-service communication
  • Exactly-Once Semantics - Reliable processing with RocksDB state store

Architecture Overview

User → Order Service → Kafka (order-created)
                         ↓
            ┌────────────┴────────────┐
            ▼                         ▼
      Payment Service          Stock Service
            │                         │
            ▼                         ▼
    Kafka (payment-events)   Kafka (stock-events)
            │                         │
            └────────┬────────────────┘
                     ▼
        ⭐ KAFKA STREAMS JOIN ⭐
         (OrderStreamProcessor)
                     │
                     ▼
          Kafka (order-events)
                     │
        ┌────────────┼────────────┐
        ▼            ▼            ▼
   Order Svc    Payment Svc   Stock Svc
   (Update)     (Confirm/     (Confirm/
   (Status)      Rollback)     Release)

Testing

Run all SAGA test scenarios:

./test-orders.sh

Tests 5 scenarios: CONFIRMED, REJECTED, ROLLBACK (payment fails), ROLLBACK (stock fails), multi-item orders.

Logs

tail -f logs/order-service.log    # Kafka Streams join logs
tail -f logs/payment-service.log
tail -f logs/stock-service.log

Kafka UI

Browse topics and messages: http://localhost:8080

About

Example microservices showing how to use Kafka and Kafka Streams with Spring Boot on the example of distributed transactions implementations with the SAGA pattern

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages