We have been using Platform Events for a while now for certain core processing. When we created our Platform Events I don't recall there being an option to specify how publishing behaved. Publishing was (and is still, for our events) processed "decoupled" from the originating transaction. I see now that there's a "Publish Behavior" setting on the event:
This is one of "Publish Immediately" or "Publish After Commit", with behaviours as explained in the above screenshot.
Part of the reason we adopted Platform Events for triggering certain in-app processes was to ensure that the records created and managed within it are recorded as created or modified by the Automated Process user, rather than the user who initiated the processing. This adds clarity as to how certain records were created/updated.
Now, we've found a nasty edge case scenario where our processing of the platform event happens too quickly, in solutions with lots of process builders etc., before the originating transaction has committed its data to the database. This means the processing initiated from the event trigger doesn't see this new data (despite itself being asynchronously invoked from the platform event trigger).
As such I am looking to change the publish behaviour for the events to "Publish After Commit".
The documentation for Apex Triggers for platform events states:
Unlike triggers on standard or custom objects, triggers on platform events don’t execute in the same Apex transaction as the one that published the event. The trigger runs asynchronously in its own process under the Automated Process entity.
I just wanted to verify that this holds true regardless of publish behaviour, before updating our package's platform events. Do you know if that's the case?