SQL Persistence Saga concurrency

SQL Persistence honors concurrency semantics in the following way.

Concurrent access to non-existing saga instances

The persister uses unique key constraints that will result in an exception being thrown should two saga instances with the same correlation value be 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