Concurrency issues

I am occasionally getting errors related to concurrency. My code is trying to expect the situation and due to command handling logic it is trying to retry the failed command.

It looks like that occasionally writing data to EventStoreDB takes a little bit longer (the appendToStream() method does not finish quickly) at which point I am not able to read newly written events from readStream() method.

This leads to a situation where the subsequent appendToStream() call fails. Adding a progressive delay seems to help.

My question:

  • how the concurrency is handled within the EventStoreDB (e.g. what to expect if I perform append/read quickly) and is there a recommended approach to re-try (what should the eventual delay be)?

What client are you using ?
AppendToStream is async, are you awaiting completion before reading ?

Good point - yes - I was checking this.

From the additional log entries I put there it looks like the following occasionally happens:

  • appendToStream() somehow updates the stream but is not fully finished yet
  • in such case the readStream() doesn’t return events which are not fully written yet although another appendToStream() already knows that the stream version already changed
    • perhaps important to mention here might be that the readStream() is trying to read only newly written events