In a Saga, if one step fails, data consistency is maintained by running compensating actions that logically undo the effects of previously completed steps, since there's no shared transaction to simply roll back.
In a travel booking saga covering flight, hotel, and car rental, if the car rental step fails after the flight and hotel were successfully booked, the saga triggers a "cancel flight" compensating action and a "cancel hotel" compensating action, returning the whole booking to an unbooked state.
// Compensate completed steps in REVERSE order, and make every
// compensation idempotent so it is safe to retry
public void bookTrip(Trip trip) {
Deque<Runnable> compensations = new ArrayDeque<>();
try {
flights.book(trip);
compensations.push(() -> flights.cancel(trip.id()));
hotels.book(trip);
compensations.push(() -> hotels.cancel(trip.id()));
cars.book(trip); // fails
compensations.push(() -> cars.cancel(trip.id()));
} catch (Exception e) {
while (!compensations.isEmpty()) {
compensations.pop().run(); // hotel cancelled, then flight
}
tripRepository.markFailed(trip.id(), e.getMessage());
}
}A concise interview answer is
When a saga step fails, I rely on predefined compensating actions for every previously completed step — for example, if a car rental booking fails after flight and hotel succeeded, I'd trigger cancellation events for both the flight and hotel to logically undo them. Since there's no shared transaction, consistency comes from these business-level compensations rather than a database rollback.
Last updated: 1 November 2026
Previous question: How would you handle distributed transactions in a microservices architecture? Explain the concept of the Saga pattern.