What is a saga in event sourcing?

What is a saga in event sourcing?

Saga is a sequence of transactions that updates every service and announces a message or event to trigger the next step in the transaction. If somehow a step fails, the saga pattern executes a transaction that compensates to prevent the preceding transaction.

What is a saga CQRS?

The term saga is commonly used in discussions of CQRS to refer to a piece of code that coordinates and routes messages between bounded contexts and aggregates.

What does saga stand for in microservices?

Azure. The saga design pattern is a way to manage data consistency across microservices in distributed transaction scenarios. A saga is a sequence of transactions that updates each service and publishes a message or event to trigger the next transaction step.

What is the difference between saga orchestration and saga choreography?

A saga is a sequence of local transactions. Choreography – each local transaction publishes domain events that trigger local transactions in other services. Orchestration – an orchestrator (object) tells the participants what local transactions to execute.

How are sagas used in event sourcing software?

This could be generalized into the following: Sagas listen to events and dispatch commands while aggregates receive commands and publish events. Sagas manage process . They contain business behavior, but only in the form of process.

When do sagas send out a timeout message?

The saga could implement a timeout by scheduling a timeout message to be sent back to the saga after 48 hours. When the timeout message was received 48 hours later, the saga would attempt to perform the state transition related to the timeout. If the customer did something in the last 48 hours, the timeout message wouldn’t cause a state transition.

Are there any sagas that contain business logic?

Sagas, in their purest form, don’t contain business logic. During Greg Young’s workshop, he hammered this one pretty hard. Most programmers think “logic” and aren’t used to thinking “process”. Let me put it this way.

Why do we need a saga in CQRS?

Perhaps we should explain why a saga is even necessary when we have aggregates and domain objects that manage state. Aggregates are great business objects that wrap a lot of business complexity. The problem with aggregates is that they only care about their little part of the universe. Sagas, on the other hand, are coordinating objects.