# Optimistic concurrency and idempotence
Append operation supports an optimistic concurrency (opens new window) check on the version of the stream to which events are appended.
The .NET API has constants which you can use to represent certain conditions:
| ||Disables the optimistic concurrency check.|
| ||Specifies the expectation that target stream does not yet exist.|
| ||Specifies the expectation that the target stream has been explicitly created, but does not yet have any user events appended in it.|
| ||Specifies the expectation that the target stream or its metadata stream has been created, but does not expect the stream to be at a specific event number.|
| ||The event number that you expect the stream to currently be at.|
If the optimistic concurrency check fails during appending, a
WrongExpectedVersionException is thrown.
If identical append operations occur, EventStoreDB treats them in a way which makes it idempotent. If a append is treated in this manner, EventStoreDB acknowledges it as successful, but duplicate events are not appended. The idempotence check is based on the
stream. It is possible to reuse an
EventId across streams whilst maintaining idempotence.
The level of idempotence guarantee depends on whether the optimistic concurrency check is not disabled during appending (by passing
ExpectedVersion.Any as the
expectedVersion for the append).
# If you specify an expected version
expectedVersion is compared to the
currentVersion of the stream. This will yield one of three results:
expectedVersion > currentVersion- a
expectedVersion == currentVersion- events are appended and acknowledged.
expectedVersion < currentVersion- the
EventIdof each event in the stream starting from
expectedVersionare compared to those in the append operation. This can yield one of three further results:
All events have been committed already - the append operation is acknowledged as successful, but no duplicate events appended.
None of the events were previously committed - a
Some of the events were previously committed - this is considered a bad request. If the append operation contains the same events as a previous request, either all or none of the events should have been previously committed. This surfaces as a
# If you specify
Idempotence is not guaranteed if you use
ExpectedVersion.Any. The chance of a duplicate event is small, but is possible.
The idempotence check will yield one of three results:
None of the events were previously committed - the events are appended and the append operation acknowledged.
Some of the events were previously committed - this is considered a bad request. If the append operation contains the same events as a previous request, either all or none of the events should have been previously committed. This currently surfaces as a