multiple writer services with Idempotency guarntees?

If I have process stream for some workflow, like application-{app-guid} and i have multiple microservices watching for certain events that then write new events to that same application-{app-guid}, say, an event comes in and sends two services off to query two APIS and then write back to the stream with the data, doesn’t this necessarily create race conditions if I want to guarantee idempotency? Each stream will check the version and write +1.

Do I need to maintain some sort of threadsafe global stream version state or is there a fundamental design problem with this situation?

set expectedversion and use a deterministic uuid. idempotency is assured then.

I have dterministic uuids. Do I understand that the expected version will always be current version + 1? If that’s the case and I have two incoming writes, what happens if one writes after the other reads?

Then you get a concurrency issue as you would expect with optimistic concurrency.

Right, so is the answer to only have one writing service per stream? Or is this just ignored is an unlikely event (assuming mean event frequency) in practice?

If they both generate deterministic uuids they are idempotent.

Ok, thanks.