6

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

2
  • With custom logging we can try to reduce the chance of getting lost.
    – Ysr Shk
    Aug 20, 2020 at 3:45
  • I have the exact same question! Have you got a response? I guess yes by now even on a different channel or based on real-life experience. What would be your recommendations?
    – fcathala
    Jun 29, 2022 at 10:18

2 Answers 2

0

You probably would have to implement the <Database.SaveResult> and catch any errors on the Event.Publish(List) that way. I would also introduce a custom object to log those erros. eg. Erro_log__c that has parameters such as : StackTrace__c, StatusCode__c, ErrorMessage__C( basically whatever you guys need).

https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_apex.htm

The above link has an example of the <Database.SaveResult>, the Errorlog__c object logic would have to be written to accommodate your needs.(insert fields)

Probably a daily batch that deletes older records so you guys don't clump up your storage as well.

How do we bulkify platform event triggers to retry on failures?

this link might also be helpful

Cheers :)

-2

Please check this You can keep track of the published events very easily using this.

https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_callback_example_success.htm

New contributor
SFDCLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 2
    Link only answers are generally frowned upon here, because links lose their validity more quickly than the explanations they point at. The answer would greatly benefit from a summary of the solution. Apr 18 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .