Event and Separation of De-concerns
msa reactive
Event and Separation of De-concerns
Internal Event vs External Event:
- The purpose of Internal Event is Separation of De-concerns.
- The purpose of External Event is Reduce coupling with an external system.
- Internal events exist in the same application.
When a member order:
- Create Order
- Processing Payment (External Event)
- Reduce Product Amount (External Event)
When a member logs in:
- Change membership to login status (Core Domain Logic)
- Handling logouts to other devices with the same account logged in according to the "Limit the number of logins to the same account" rule
- Record which device the member is logged in from
- Log out of other accounts on the same device
2,3,4 are Policies that must be performed together when a domain action is performed. It's called De-concerns.
How to reduce coupling Using Event
When an event is published, if the purpose
is included, a coupling occurs.
Publishers should not be interested in what the subscriber does.
Therefore, external events should be treated as domain events themselves to reduce coupling between services.