Integration / Apache Camel Interview Questions
What is the Saga EIP in Camel and when would you use it for distributed transaction management?
The Saga EIP implements the Saga pattern for managing long-running distributed transactions without using two-phase commit (2PC). A saga is a sequence of local transactions coordinated by a compensation log: if any step fails, previously completed steps are rolled back via compensating transactions.
The Saga EIP is used when you need consistency across microservices that each own their own database and cannot share a single ACID transaction — for example, booking a flight, hotel, and car in one business flow where each service is independent.
from("direct:book-trip")
.saga()
.compensation("direct:cancel-trip") // run if saga fails
.completion("direct:confirm-trip") // run on success
.to("direct:book-flight")
.to("direct:book-hotel")
.to("direct:charge-card")
.end();
from("direct:cancel-trip")
.to("direct:cancel-flight")
.to("direct:cancel-hotel");Camel integrates with the LRA (Long Running Actions) specification via the camel-lra component, which uses a coordinator service. The Saga EIP guarantees eventual consistency rather than strict ACID consistency. It is the right choice for microservice choreography where 2PC would create tight coupling or lock contention.
More Related questions...