Damian Hickey

Mostly software and .NET related. Mostly.

A word NEventStore concurrency

NEventStore implements optomistic concurrency for Commits based on the StreamId and CommitSequence (and BucketId in v5). The exact implementation of which depends on the persistence engine. For instance, for SQL storage engines it is enforced by a primary key. This means if you open the same stream twice concurrently, add a commit, and close, you will get a ConcurrencyException:

IStoreEvents store = Wireup
	.Init()
	.UsingInMemoryPersistence()
	.Build();

Guid streamId = Guid.NewGuid();
using (var stream1 = store.OpenStream(streamId, 0, int.MaxValue))
using (var stream2 = store.OpenStream(streamId, 0, int.MaxValue))
{
	stream1.Add(new EventMessage{ Body = "test"});
	stream2.Add(new EventMessage{ Body = "test"});
	stream1.CommitChanges(Guid.NewGuid());
	stream2.CommitChanges(Guid.NewGuid()); // throws ConcurrencyException
}