Trying to understand concurrency with CQRS, I came across that question: https://softwareengineering.stackexchange.com/a/349575/286881
But there is something I don't understand when it is said that:
it do so by appending the new events to the Event stream if and only if the version of the Aggregate is still the one that was when the Aggregate was loaded.
To check the current version of the Aggregate against the one I have, I first need to retrieve it. Then, if it matches, I can append the events to the Event Store. Maybe I'm missing something but should not these steps be done atomically? If so, how is it achieved?