Because it’s hard to write idempotent code effectively, NServiceBus provides the outbox feature to make your business data transaction and any sent or received messages atomic. That way, you don’t get any ghost messages or zombie records polluting your system. 1
This is a companion discussion topic for the original entry at https://particular.net/blog/transactional-session
I’m really wary of “magic” middleware that manages database transactions. It feels like a violation of separation of concerns when http middleware takes over the concern of database transactions. I’m not saying that it won’t work, but I generally do not want to deal with databse code that leaks out of the repository layer.
The article isn’t about HTTP middleware to manage database transactions. The article is talking about how to make database transactions initiated by the web tier consistent with messages sent to the backend so that the entire operation is atomic. You can’t do that with just a database transaction in the repository layer.
The alternative is to only send a message from the web tier and do all the database work on the backend.
That isn’t happening as NServiceBus doesn’t know anything about your business data. The NServiceBus outbox table needs to share the same database to share the same transaction that your repository object is also using and that is it.
Curious to hear from you @Don_Rolling how you manage the unit of work that surrounds your repository layer?