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:

  1. Create Order
  2. Processing Payment (External Event)
  3. Reduce Product Amount (External Event)

When a member logs in:

  1. Change membership to login status (Core Domain Logic)
  2. Handling logouts to other devices with the same account logged in according to the "Limit the number of logins to the same account" rule
  3. Record which device the member is logged in from
  4. 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.