18

I'm intrigued by Platform Events, but I have a few questions about how they operate:

  1. Are the subscription triggers processed synchronously or asynchronously?
    • The developer guide makes it clear that the publish part of the pub/sub is synchronous. But I haven't yet ascertained if that also applies to the subscribe part.
  2. Do the subscription triggers get separate limits from the publishing context?
  3. If the limits are separate, does each subscription trigger get its own set?
1
  • In my testing they are async. Will check about multiple triggers. Commented May 12, 2017 at 6:58

1 Answer 1

19

Are the subscription triggers processed synchronously or asynchronously?

Aynchronously

Do the subscription triggers get separate limits from the publishing context?

Yes, separate limits from the publishing context

If the limits are separate, does each subscription trigger get its own set?

Each Apex subscription trigger executes in its own transaction with independent limits.


To back these claims up I create a test platform event with two Apex trigger subscriptions. I then executed a publish for 300 events via anonymous Apex.

There were 5 independent transaction logs generated. One for the Tooling API execute anonymous, followed by 4 "Platform Event Trigger" operations. Historically each log entry has always represented a separate transaction (with their own limit). I'm assuming the same applies here. I'll add some more limit logging to back that up.

Sequence of logs for my second test attempt:

  • Operation /services/data/v40.0/tooling/executeAnonymous/ to publish the 300 events. Timestamp: 7:57:09 PM
  • Operation Platform Event Trigger 2nd Apex trigger with CPU Limit at 36 with last DEBUG message. Trigger.new size of 300. Timestamp: 7:57:11 PM
  • Operation Platform Event Trigger 1st Apex trigger with CPU Limit at 23 with last DEBUG message. Trigger.new size of 200. Timestamp: 7:57:11 PM
  • Operation Platform Event Trigger 1st Apex trigger with CPU Limit at 12 with last DEBUG message. Trigger.new size of 100. Timestamp: 7:57:12 PM

    enter image description here

Note how my first test split 200 events to the first event trigger transaction and then 100 events to the latter transactions. Yet in my second test with the same triggers and same number of published events the second trigger only fired once for the full 300 records. Important note on potential Trigger.new size for platform events.

It can potentially go all the way up to 2000 events in one trigger transaction. Source

1
  • 3
    +1 I suspected that was the case, but I do wish the documentation said something more explicit about the nature of the transactions.
    – sfdcfox
    Commented May 12, 2017 at 14:16

You must log in to answer this question.

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