Knowing if you have written a duplicate event

Hi all,
we’d like to check during writing whether we are committing a duplicate event to a stream, or whether it’s being written for the first time.

In either case the write result will come back as a success, but I have noticed that on writes where all events are duplicates the LogPosition.CommitPosition is always listed as -1.

Is this dependable behaviour, or should it be considered an internal implementation detail? If it isn’t safe to rely on, is there anyway to tell if a write is a duplicate?



Hmm I am wondering if CommitPosition should be -1 there, an idempotent
write should return exactly the same thing as original by definition.


I was a bit surprised it was different (as you say, by definition) but it would be quite convenient in this case if it was…


Why do you need to know if a write was idempotent (you really shouldn't care)

It’s useful if you want to not do something if it was a repeat event. In our case we want to abstain from sending an e-mail if the write was idempotent (i.e. ignored because of existing event with same id). That way we don’t have to provision a RDBMS to use transactions.

I was curious for nearly the same answer. If I AppendToStreamAsync with the same EventId and ExpectedVersion.Any (or StreamExists if that makes a difference) twice, does it return the same WriteResult (especially NextExpectedVersion)?

My particular use case is for assigning IDs to new streams using an ID stream. Current implementation requires client to first call API to get an ID (which just appends blank event to ID stream with ExpectedVersion.Any and returns WriteResult.NextExpectedVersion as the integer portion of the stream ID), then client issues command with new ID. If the above idempotency question holds true, then the client would only have to make 1 call. I’d need to use the CommandId as the EventId in the ID stream, but then the client could retry safely.