Projections for partitioning events as part of a domain model

I’m wondering if it is a good design approach to make a user-defined projection part of the domain model?

I have persistent subscriber email processor services. Each service processes emails from a specific mailbox. Dedicated stream is created for each email. Each email stream email-{emailUuid} is very short: emailCreated(inMailboxUuid).

My user-defined projection projects email streams to mailbox-specific email streams: email.mailbox.{mailboxUuid}-email.{emailUuid}.

Each email processor service subscribes to stream $ce-email.mailbox.{mailboxUuid} ($by_category projection is anyway enabled).

Would it be better to partition the email streams at the first place by mailbox thus eliminating the need for the projection? So the emailCreated events would be appended to email.mailbox.{mailboxUuid}-email.{emailUuid} right away.

Remark
In the above stream design I have been trying to avoid long streams with growing number of events e.g. one stream for each mailbox with growing emailCreated events.

Let me summarize to make sure I understand :

  • Stream : email-{emailUuid}
    • containing emailCreated(inMailboxUuid)
  • Stream : email.mailbox.{mailboxUuid}-email.{emailUuid}
    • linkin all emailCreated from the mailboxUuid
    • created by a user defined projection

Would it be better to partition the email streams at the first place by mailbox thus eliminating the need for the projection? … email.mailbox.{mailboxUuid}-email.{emailUuid}

I think I would do that indeed, just append directly to the above and not create any email-{emailUuid} stream since you have already the MailboxUuid
Consuming them would still use the $by_category

Are there any other events that have to do with email.mailbox.{mailboxUuid} or email-{emailUuid} streams ?
Any other type of processing ?

1 Like

Your summary is correct!

Are there any other events that have to do with email.mailbox.{mailboxUuid} or email-{emailUuid} streams ?

Yes, we may add emailMoved(targetMailboxFolder) etc. later if needed.
With your question are you referring to the fact that streams where projections emit events to cannot be used to append events from applications pls.?

Any other type of processing ?

Not planned yet. We just process emails and then move them to another folder in the mailbox depending on the completion status of the processing.

Yves, many thanks!

are you referring to the fact that streams where projections emit events to cannot be used to append events from applications pls.?

Yes inded .

And with little knowledge where you want to go with this system I’d keep the door open for having those streams owned by the application instead of the projection engine .

I kind of suspect that later on there will be something some email.mailbox-{mailboxUuid} streams as well .

Whising you success !

1 Like