I'm coming to a point where my software does to many things at the same time, so I decided to switch to Platform Events to decouple everything. I don't handle external events, I'm only planning to use it natively with apex.
Now I face some issues with a proper design behind it and wonder if anyone else already came up with something like best practices and/or platform specific requirements that could help me out here. Is there any Architectural Library to structure the Platform Event Trigger handling similar to how the fflib supports general Trigger handlers?
I couldn't find anything on google and the success community.
Things that aren't clear for me so far:
Several Events for everything?
- Is it smart to create events like CaseInserted__e for all the possible objects i need to track, or is is smarter to have a general SObjectInserted__e event?
- If so, I would have to handle them in a dispatcher-like triggerhandler, is that a good approach? Idk. both ways still seem like an overhead to me :(
Execution context and Limits
- Are platform events a good approach to win the fight against limits?
- If so, why are they coming in batches and not one by one? this confuses me the most :( Do I always have to consider my self if I need to split them or just publish the whole batch of events?
- If I decide to use the events to decouple the code base, what kind of things should be done in regular triggers and what am I supposed to do in the events triggers?
- Will there even be a need of regular triggers anymore, or should they be replaced, or just do simple stuff like updating fields?
So the main thing is, that I don't want to do too many wrong decissions right at the beginning and if there is any knowledge out there please share it :)