Let’s say I have two bounded contexts in my system, responsible for Products
and Orders
respectively.
In the Products
context, I have services responsible for aggregates that listen to all events on product streams and keep a representation up to date, and can give current info about it. The same in the Orders
context. Both separate and working well.
Then I want to make a read side service, let’s call it CartViewService
that is able to give data about a not yet finished order with product information embedded, like { items: [{ product: 123, image: 'http://a.cdn/345.jpeg' }]}
. That is a projection of projections from two different contexts.
My design thought here is that only the Orders
context service should know about all the event types that can appear on an Order, and likewise for the Products
context. So they would each make their projections (in service code, not in EventStore projection code, for reasons outside of this topic…). And the CartViewService
, not knowing all event types, would just need to get notified on NewVersion
of the Orders and Products in that order.
I’m hesitant of the best approach here. One solution I see would be that the aggregate services, after receiving a domain event (like new-product-photo
), would publish an event on a PublicProduct-<uuid>
stream with the event type NewVersion
and the full projection of the product. That event could just go to a pub/sub message broker as well as EventStore.
Is this reasonable, or am I missing something obvious? I do NOT want the readside to need to know about all event types of products and orders or share code between these contexts.