Saga
An order choreographed over Kafka by three services with no coordinator: the saga state in order-service, a compensation that is idempotent and commutative, a sweeper for silent participants, and a semantic lock that refuses a late payment.
examples/22-saga/ carries an order from placed to paid through order-service, inventory-service and payment-service. Each publishes through the outbox, and one Debezium connector reads the three outbox tables. It accompanies Saga.
It uses Quarkus, SmallRye Reactive Messaging, Camel Kafka (in payment-service), Hibernate ORM with Panache, Flyway, the Debezium outbox extension, Quarkus Scheduler, SmallRye Health, PostgreSQL, Kafka, Kafka Connect and OpenTelemetry to the LGTM stack.
(cd examples/domain-model && mvn -B -q install)
cd examples/22-saga
mvn -B verify
./verify.sh
What to observe
- Compensation once. A declined payment ends in a cancelled order and a released reservation, and a repeated PaymentFailed is skipped by the inbox (the release is idempotent, so the stock is the same either way).
- A deadline owned by one service. With payment-service stopped, the sweeper cancels the saga after its deadline and inventory releases the stock.
- A late reservation refused. When payment-service returns, it waits until it has read the cancellations and takes no money for the cancelled order.
- State in PostgreSQL. A saga in flight is still waiting after a recreate of order-service and is cancelled at its original deadline.
Infrastructure
Kafka, PostgreSQL, Kafka Connect and the LGTM stack from examples/_infra, plus the three services on ports 8080, 8082 and 8084. The compose project is edp-22.