Sagas


To address the challenge of distributed transactions, the Saga pattern provides a solution. It involves breaking down lengthy transactions into independent units, allowing each transaction to operate autonomously. Once a transaction successfully commits, it notifies the subsequent transaction. This division of long transactions into smaller ones ensures isolation and autonomy for each individual transaction. Moreover, the saga pattern incorporates a rollback compensation mechanism for each transaction, enabling the restoration of the original state and ensuring data consistency in the event of a failure.

Types of Saga

The coordination between transactions can be implemented in two ways:

  • Choreography-based Saga
  • Orchestration-based Saga

The Crystal Sharp framework offers the flexibility to utilize sagas based on either Choreography or Orchestration principles.

Saga Store

At Saga Store, transaction statuses are effectively managed and maintained. The Crystal Sharp framework provides the capability to seamlessly integrate with a variety of databases, allowing for efficient management of transaction states.

The following databases are supported for the saga store:

Microsoft SQL Server To use Microsoft SQL Server as a saga store.
PostgreSQL To use PostgreSQL as a saga store.
MySQL To use MySQL as a saga store.
MongoDB To use MongoDB as a saga store.

Following are the NuGet packages for each saga store:

NuGet Package Database
CrystalSharp.MsSql Microsoft SQL Server
CrystalSharp.PostgreSql PostgreSQL
CrystalSharp.MySql MySQL
CrystalSharp.MongoDb MongoDB

Saga States

The saga store maintains the state of the saga as an integer type, which is essentially an enum.

The following list represents the saga states that correspond to the enum:

0 New
1 Committed
2 Active
3 Aborted