We are in the process of redesigning our system to use platform events as a replacement of traditional trigger-based approach when all processing happen synchronously sharing single transactional scope.
The concern we currently have is how to actually track whether platform event has been published successfully by SF or not. In other words, whether all events published from our apex code would end up in SF event queue to be available for subscribers to process. Is it rare/possible to lose some events on their way to be published?
Starting Spring 19 all newly created platform events are considered to be high-volume. And according to SF docs, even publishing of high-volume events happens asynchronously, i.e. no way to figure our whether event was published successfully or not based on Database.SaveResult object returned in response of calling EventBus.publish method:
Platform events are temporarily persisted to and served from an industry-standard distributed system during the retention period. A distributed system doesn’t have the same semantics or guarantees as a transactional database. As a result, we can’t provide a synchronous response for an event publish request. Events are queued and buffered, and Salesforce attempts to publish the events asynchronously. In rare cases, the event message might not be persisted in the distributed system during the initial or subsequent publish requests. No mechanism surfaces these types of errors to the publishers or consumers of the event streams.
Based on the above:
- is there any way to figure out whether event was published or not
- how often it may happen that event is 'lost', i.e. not published successfully by SF itself
- is it a reliable approach to rely on a platform event to execute some important /crucial business logic in the system, i.e. when it's not allowed to miss anything (should be executed in 100% of cases) - can we achieve this with platform events?
Any suggestions would be appreciated