NServiceBus Saga


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?

  1.  For Long running Business processes.
  2.  Chain of seperate transaction -Workflow
  3.  Incase of Microservices solve distributed transactional consistency [Distributed sagas]
  4.  Fault tolerance

How Sagas are implemented?
Stateful– Data Persistent

NServiceBus Saga implementation:
Major interfaces to be inherited for creating NServiceBus Saga Message Handler Class.

  • Saga<T>
  • IContainSagaData

IAmStartedByMessages<T>    Start of the Saga Message Handler to initiate

  • IHandleMessages<T>  _ Simple handler

Override  ConfigureHowToFindSaga

Simple Saga class implementaion inherit from above interfaces.
Public class MigrationSaga : IContainSagaData,  IAmStartedByMessages<T>,IHandleMessages<T>