SQL Persistence saga concurrency

Component: Sql Persistence
NuGet Package NServiceBus.Persistence.Sql (4.1)
Target NServiceBus Version: 7.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

To ensure correctness, when creating new sagas, the persister applies optimistic concurrency using an incrementing counter. The persister uses an explicit version column combined with the ReadComitted isolation level.

However, to avoid excessive conflicts for highly congested sagas, the persister uses pessimistic concurrency for querying and updating saga information. The pessimistic concurrency is implemented using a SELECT ... FOR UPDATE construct or its dialect-specific equivalent.

Related Articles

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

Last modified