What is the Saga pattern in microservices?

Answer

The Saga pattern manages long-running distributed transactions across multiple microservices without using a two-phase commit. A saga is a sequence of local transactions, each updating one service's database and publishing an event or message to trigger the next step. If any step fails, the saga executes compensating transactions to undo the completed steps. There are two coordination styles: Choreography, where each service reacts to events and publishes new events with no central coordinator (simpler but harder to observe), and Orchestration, where a central saga orchestrator explicitly commands each participant and handles failure logic (more visible and easier to debug). Sagas are essential for order checkout flows, booking systems, and any multi-service business transaction.