“ A Saga is a Long Lived Transaction that can be written as sequence of transactions that can be interleaved. All transactions in the sequence complete successfully or compensating transactions are ran to amend a partial execution. “ Coined By- Hector Garcia-Molina, Kenneth Salem Princeton University 1987
- A saga is a collection of Sub – transactions
- Each sub request has a compensating request.
Why we need Sagas?
- For Long running Business processes.
- Chain of seperate transaction -Workflow
- Incase of Microservices solve distributed transactional consistency [Distributed sagas]
- Fault tolerance
How Sagas are implemented?
Stateful– Data Persistent
NServiceBus Saga implementation:
Major interfaces to be inherited for creating NServiceBus Saga Message Handler Class.
IAmStartedByMessages<T> Start of the Saga Message Handler to initiate
- IHandleMessages<T> _ Simple handler
Simple Saga class implementaion inherit from above interfaces.
Public class MigrationSaga : IContainSagaData, IAmStartedByMessages<T>,IHandleMessages<T>