SQL Persistence saga concurrency

Component: Sql Persistence
NuGet Package NServiceBus.Persistence.Sql (1.x)
Target NServiceBus Version: 6.x

SQL persistence honors concurrency semantics in the following ways.

Concurrent access to non-existing saga instances

The persister uses unique key constraints that will result in an exception being thrown if two saga instances with the same correlation value are created at the same time.

Concurrent access to existing saga instances

The persister provides optimistic concurrency using an incrementing counter.

This means that the relevant Handle method on the saga will be invoked, even though the message might be later rolled back. Hence it is important to ensure not to perform any work in saga handlers that can't roll back together with the message. This also means that should there be high levels of concurrency there will be N-1 rollbacks where N is the number of concurrent messages. This can cause throughput issues and might require design changes.

Related Articles

  • Saga Concurrency
    NServiceBus gives ACID semantics, using underlying storage so only one worker thread hitting a saga instance can commit.

Last modified