AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/persistence/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Sagas with DynamoDB persistence

Target Version:
NServiceBus 8.x
Standard support for version 8.x of NServiceBus has expired. For more information see our Support Policy.

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
    Master NServiceBus sagas to coordinate distributed workflows and ensure reliable long-running processes.