When Bother with Events
We are talking here about application events - the application-level (architecture-wise) means to decouple a caller and a callee. When you aren't gonna need it (YAGNI) and when you do actually need events.
Note, we are not talking domain events. Them better be called domain facts instead, to avoid a clash of meanings. After all, the event-driven architecture (EDA) is, in a nutshell, a bus and an event (with an optional payload). EDA is the application-level approach (not a problem domain notion) created to decouple the caller and callee, not to specifically deliver domain facts, but used for that as well.
So, the scenario is this: we have to call some functionality. You have a caller invoking a callee. The simplest approach is a direct call (synchronous or asynchronous), so we default to this whenever possible.
When You Better Do With Events
The following 4 practical scenarios - the rules of thumb - to decide if we actually have to bother with events. The scenarios effectively cover all the major reasons for using events.
-
Long wait for a callee operation result: Implement a long-running task in a callee; in a caller, fire the event the callee will listen to and execute the task on it. Treat the results in different parts of your application;
-
Many callees exist: Avoid the complexity of managing multiple direct calls to different callees, make them listen and act on the same (or a few) event(s) and let the caller fire the event(s);
-
Unknown event receivers: allows adding new listeners without modifying the caller's code. Let the caller fire the event and forget. Other places in the application will have to take care of the results.
-
Resilience: A failing callee must not break the caller. Or the caller does not want to bother with the errors processing. So it fires the event and lets the callee treat errors as it sees fit;
All the basic principles - SoC 1, SRP 2, low coupling 3 - high cohesion 4 - are fully applied here. But in daily practice, based on these, we need comfortably clear rules of thumb.
Now you have got these :)