Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Sagas (DynamoDB)

NuGet Package: NServiceBus.Persistence.DynamoDB (2.x)
Target Version: NServiceBus 9.x

This article describes how to configure NServiceBus sagas for use with DynamoDB

Configure the saga table

The saga data table can be configured as follows:

persistence.Sagas().Table = new TableConfiguration
{
    TableName = "MySagaTable",
    PartitionKeyName = "MySagaPartitionKey",
    SortKeyName = "MySagaSortKey"
};

Saga data mapping

Saga data is automatically mapped using the built-in mapper described in the transaction documentation.

Saga concurrency

The DynamoDB saga persister uses optimistic concurrency control by default. Concurrently processed messages modifying the same saga will fail when the saga transaction completes after executing the message handler. In high-contention scenarios, pessimistic locking can enforce sequential access to the same saga to avoid concurrency related retries. To enable pessimistic locking, use:

persistence.Sagas().UsePessimisticLocking = true;

For more information, refer to the saga concurrency documentation.

Pessimistic locking configuration

Pessimistic locking is implemented using leases. The lease duration determines the amount of time exclusive access is guaranteed before other readers are able to acquire a lease again. The default duration is 30 seconds. To change the lease duration:

persistence.Sagas().LeaseDuration = TimeSpan.FromSeconds(15);

When a client attempts to acquire a lease on a saga data record that is locked, it will retry acquiring a lease for a configurable amount of time before timing out. The default retry duration is 10 seconds and can be changed with the following code:

persistence.Sagas().LeaseAcquisitionTimeout = TimeSpan.FromSeconds(5);

Related Articles

  • AWS DynamoDB persistence
    How to use NServiceBus with AWS DynamoDB.
  • Sagas
    Maintain statefulness in distributed systems with the saga pattern and NServiceBus' event-driven architecture with built-in fault-tolerance and scalability.