Correlating aggregates by Saga ID instead of an additional aggregate root

282 views Asked by At

That's my first question ever, so excuse me if it's unclear or incomplete, and let me know how I can provide more info.

I'm trying to build an email ticketing system using CQRS + ES. So emails are joined into conversations (sort of a la outlook conversations, but with different criteria for joining) and these conversations are then assigned a ticket where people can interact with (tag it, update its status, add notes...).

Currently, once an mail is received, a new Mail aggregate is created which raises a MailReceived event.
ProcessManager router (or saga router) tries to find a matching "ConversationSaga" based on the criteria or creates a new one. The saga sends a command to assign the conversation Id to the Mail aggregate --> which raises a ConversationAssigned mail.

The last event, ConversationAssigned, is intercepted by the Ticketing bounded context that generates a ticket or update an existing one based on the conversation Id. once ticket is created/updated, the event is routed to the ConversationSaga to send needed commands (ApplyTicketToMail --> MoveMailToFolder --> ...)

My questions are:
1- is it abnormal to use Saga Id as the conversation Id linking several mails together?
2- I was checking the possibility of creating a Conversation Aggregate root, but i'm still new to event sourcing and don't know how to handle event sourced entities within AggregateRoots (i need Mail to be an event sourced aggregate).

PS: i'm using C#, with MsSql DB and nhibernate and messaging is over RabbitMq.

1

There are 1 answers

2
Alexander Langer On

I have some problems to read/understand your descriptions, but the overall design seems fine to me. In particular, it is common practice to orchestrate multiple ARs from a single saga.

From what you wrote, I would indeed suggest to create a new Conversation aggregate that is decoupled from the Mail AR, in particular since you already named it like that ("conversation"), and thus it appears to be a term from the ubiquitous language.