Let's assume I was building a collaborative document editing platform ala Google Docs.
Collaborators work together on a
Collaborator must be a user of the platform.
Comment subdomain that allows
Collaborators to communicate within a
Comment is created, all
Collaborators should be notified according to their account notification preferences (email, SMS or both).
The notification preferences is stored in a seperate
How can I notify the users whilst maintaining clean separation of my domains?
The options I see:
CommentPosteddomain event from within the
Commentdomain and listen to the event within a
Commentapplication service, which makes a call to the
Userdomain for the users and then invokes the
EmailServiceto send an email. The issue here is now the
Commentapplication service knows about and is coupled on the
Userservice listen to the
CommentPostedevent. With event-carried state transfer the
Userservice should have enough knowledge to formulate and send the email. Still, not sure that it's a good idea for the
Userservice to know about
CommentPostedevent (then again, isn't that part of the idea behind an event-sourced system?).
CommentPostedfrom within the
Commentdomain but this time have the handler fire off a
SendEmailCommandmessage. Have an infrastructure email service (most likely a microservice) listen to the
SendEmailCommand. The email service can then make a request to the
Userservice to get the email (and probably have it's own cache of
This seems to be the most generic approach but it does mean the Email infrastructure service now needs some understanding of domain constructs (namely, the
UserId). Again, I'm not entirely sure that this is a bad thing.
At the moment, the Email service is basically just a dumb
portto an external email service with one method:
Email.sendEmail(Email email). In this case, it'll might need to change to
Email.sendEmail(User userId, Email email).