NServiceBus Unique attribute – A painful lesson

In NSB v 3.3.5 you can add a [Unique] attribute to a property of a saga’s state class. This ensures NServiceBus will only create one saga instance for each property value. This also increases performance when the saga is found using the property. In NSB v3.3.5 when you do this NServiceBus will create a SagaUniqueIdentity document when the saga is created that will ensure uniqueness across all instances of the saga in RavenDB.

Our issue was that we added the [Unique] attribute after having already deployed the saga code to production. We did not realise that in addition we needed to create a tool that would generate SagaUniqueIdentity docs for all existing saga instances. If you fail to generate the SagaUniqueIdentity docs, the next time a saga message is handled NServiceBus will not find the existing saga and will create a duplicate saga doc with blank state. Needless to say this is a bad thing.

In NSB v4.0+ if you introduce custom saga finding logic like the example below but you forget to add the [Unique] attribute to the saga state class you will get a warning (I think at compile time).


public override void ConfigureHowToFindSaga()
        ConfigureMapping<Message2>(s => s.SomeID, m => m.SomeID);



RavenDB Feature Wish List

Note that I’m using Build #992 so maybe these features exist in more recent versions.

  • Backup Compression. (Ability to compress a backup as it is being created.)
  • Gui Tool for Backup/Restoring Databases (Ideally inside Raven Studio).
    • Found this under the Tasks menu, ┬áimport/export/backup a db
  • Ability to Restore a Database without stopping the Raven Service.
    • you can’t restore online but you can import which may achieve the same.