In Summer ’17 Salesforce released Platform Events – a native messaging system accessible via Apex and several APIs.
I assume the main use case for such a feature is to allow integration of Salesforce apps into the SOA of a company meaning connecting Salesforce with other enterprise systems.
But…wouldn’t Platform Events also be of great help in many native and standalone Salesforce applications? Especially more complex ISV applications?
I’m thinking of Domain Events as Eric Evans defined them in his book which are different than Integration Events as described here.
What’s your opinion on this (the most detailed and complete answer will be credited.) Couldn’t Platform events also help app developers to:
- Decouple monolithic, synchronous Apex apps into an architecture of micro services. Something similar that OSGI or IOC Containers like Spring do. You can find more details in this question Implement Domain Event Pattern in Apex – can and should it be done?
- Solve Governor Limit problems by pulling code before and after triggers apart into separate execution contexts
- Build a communication channel between Base and Extension Packages without global Apex classes.
Replacing tightly-coupled synchronous Apex code which guarantees all-or-nothing consistency with a loosely coupled asynchronous world surely has many drawbacks. If Salesforce.com had those other use cases in mind I would expect them to also provide solutions for that in the next releases.
This very recent talk by Martin Fowler about The Many Meanings of Event-Driven Architecture contains a lot of wisdom that can help when thinking about how to use this feature in the Salesforce.com ecosystem.
- A classic use case is to decouple a Salesforce app from other enterprise systems using events (trivial answer)
- Event can also used internally (just look at how Lightning components work together using low-coupled events
- Apex code can use command-style and tell what to do OR make changes a first-class code citizen and model state changes explicitly using events
- Event-based decoupling makes software more flexible but also harder to understand (“What’s going on when XYZ happens?”) and debug
- Use Event-Sourcing to seperate the Application State and a Log of all the Events/Changes that created this state (comparable to Version control)