Ensuring consistency when SQL transport and persistence databases on different servers

Hi,

I have an NServiceBus 7.3 endpoint built using .NET Core 3.1 and uses NServiceBus.Persistence.Sql 6.0.1 and NServiceBus.SqlServer 6.1.1. The business data and persistence data are on the same database. The transport tables are on a different database server. Business data is handled using EF Core. The transport uses SendsAtomicWithReceive transaction mode.

I understand that Outbox needs to be used ensure consistency between messaging operations, saga persistence, and business data persistence in this scenario. Is that right?

Apart from using Outbox, do I also need to use the same data context used by NServiceBus internals (context.SynchronizedStorageSession.SqlPersistenceSession) to store business data? Or, is that not relevant since the transport tables are on a different database server?

Correct, when using SendsAtomicWithRecieve transaction mode, Outbox is your best out-of-the-box solution for ensuring consistency between message operations, saga persistence, and your business data.

You would still want to use the SqlPersistenceSession even when using Outbox. The Outbox also stores data using that same context, which is how it helps ensure message processing consistency.

1 Like

Thank you for the answer!

The business data access happens in a repository outside the handler. I register my data context following this documentation.

However, I use Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory as my dependency injection container. In that case, should the data context creation Func be added as a ‘scoped’ service?

You are correct, you would use Scoped is it is the equivalent ServiceLifetime to InstancePerUnitOfWork.

1 Like