commanded / commanded

Use Commanded to build Elixir CQRS/ES applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General design philosophy question: sending email from process manager

DrewEaster opened this issue · comments

Commanded is a fabulous project and a great advert for DDD in general. I have a design philosophy question regarding process managers.

Imagine a certain state change within a process manager that would mean the desire to send a notification email. From my understanding, the general pattern for process managers is event => aggregate command. This makes a lot of sense from a DDD perspective. But, what would I do in this email scenario? Can a process manager trigger other behaviour other than just sending commands to aggregates? Even if it can, should it? If a process manager can't - or shouldn't - do that, then what would the "right" approach be for this?

Using a DDD mindset, would it be better to formalise the concept of the notification as an Aggregate? i.e. have the process manager create an instance of some notification aggregate, and then use a general stateless event handler (not a process manager) to trigger the sending of an email on seeing a PendingNotificationCreated event. The handler could send a follow up command to the aggregate to let it know the email has actually been sent to the external mail system.

I've very interested to understand the philosophies for this sort of stuff, especially from those who are advanced enough as DDD practitioners to create something as excellent as Commanded!

Come chat about your issue in ‘#commanded’ channel in https://elixir-lang.slack.com

You may want to think about whether your email notification is part of your domain or not. Usually it is not. If an email must be sent after an order is cancelled, then have an event handler listen for OrderCancelled, and enqueue an email to be sent using something like Oban.

The advice for ProcessManagers is to try to keep them free of side effects. Just use them to communicate between aggregates. Use event handlers when you need side effects (email, disk or network I/O, launch missiles, etc)

Thanks @drteeth. Great advice. I'll head over the slack channel for any followups.

@DrewEaster is this still an issue?

@slashdotdash do you think it would be a good idea to enable the Discussions to ask these types of questions so people don't create issues for it?

I've enabled discussions for the Commanded repo.