Target Group: Admins, Developers, Architects
Complexity: Simple
This topic has been haunting me ever since Platform Events was introduced: Why not make async via Platform Events the default solution for transactions within the Salesforce platform?
Let me start with a simple example:
Every time an Opportunity is set to Closed-Won a set of Tasks needs to be created for the invoicing team.
Synchronous Solution: Record Trigger Flow on Opportunity that creates the Tasks
Async/PE Solution: Record Trigger Flow fires an “Opportunity Closed” Platform Event. Second Flow on PE listens to that even and creates the Tasks in its own transaction.
Differences:
1) Wait time:
The sync operation has a considerably longer wait time for the User. Async on the other hand is super fast.
2) Errors:
The sync operation shows all errors directly to the User while the async solution hides the errors from the User.
3) Loosely coupled instead of tightly coupled
The synchronous implementation tightly couples closing an Opportunity for the creation of Tasks.
The async solution can be triggered from many different places and is, therefore, more flexible.
4) Limits
The async implementation gets its own set of Limits for each “transaction/functionality”. Say goodbye to optimizing for CPU time, heap size, SOQL…
But…
1) … limits
There’s a lot of confusion around PE limits. Simply put, as long as you stay in Triggers or Flows, the limits are pretty high. As long as the consumer of the Platform Event is a trigger or Flow the limit is 250k events per hour. This should be enough for most Orgs.
2) … error handling
“Users are not supposed to replace an error log.”
Yes, errors in downstream processes will not stop the upstream process anymore, the User will not be informed about any errors. That means errors have to be logged and handled by a support team. Furthermore, debugging is a little bit more challenging.
3) … the record is not immediately there
True, the Task records from our example will not show up immediately to the User. But honestly, Users usually don’t care, they just want to close their Opportunity. From my experience, they trust the system that the tasks have been created. This is a task for BAs to understand: What does the User really need?
Storytime:
This concept is not something theoretical but I know two large Orgs that have implemented an “async by default” pattern many years ago. Works perfectly fine. Wait time for Users could be reduced by up to 80%.
Conclusion:
I think, for most requirements, an async implementation is a way to go.
Trigger Frameworks:
An async architecture (almost) eliminates the need for complex trigger frameworks because it eliminates lots of complexity that Trigger Frameworks introduce.