Hello everyone
I've spent some time adapting ddd + cqrs with eventsourcing, read the Blue book, CQRS Journey and Vaughn Vernon's "Implementing Domain-Driven Design" but some areas are still in the dark.
We're writing factory production optimization and management system. I split it to these bounded contexts:
- Production - everything related to planning, recipes to produce SKU, factories, production lanes etc
- Orders - requests and orders management
- Forecasting - sales forecasting, operations to analyze and transform that forecast
- Stocks - everything related to stocks, shipments, product distribution etc
- Integration - integration point with the client's CRM, responsible for passing validated data to the system
- UI - integration point with users of the system. Web Api to communicate with other parts
and a couple others.
1. There are 2 channels of communication with system: things that user does and things that come from integration. Does it make sense to couple them together?
For instance, now every synchronization with the client's CRM I generate commands based on the new data and send them to our system.
Pros:
- Exactly same command handlers for synchronization with the client's CRM and for users of the system
- No need to think about separate path for synchronization processing and maintain it
Cons:- Users changes come one at the time generating single command while synchronization changes always produce a lot of commands so performance is somewhat slow. I improved that situation a little by merging multiple commands into one "envelope" but i can't merge events because event handlers expect to see separate events.
- There is no way to tell that synchronization is over because events are coming separately although they were produced by single synchronization
2. Let's say that we've got multiple entries with information about stocks of some SKU on some DateTime moment. That's history data. Is it right to model it as separate aggregates? What is the best way to handle history series?
3. Let's consider that stocks data from previous question was modeled as aggregate like this:
class StockHistory : AggregateBase
{
Guid SkuId
DateTime Moment
Quantity Quantity
}
so history will consist of the array of that aggregates.
a. What if I need to group it by days? Should I do that in the read model?
b. If i group it in the read model what to do if some other context is interested in daily stocks? Is it OK for read model to publish events?
4. In the first iteration of development we tried to make every bounded context to collect all necessary information in its own read model based on other BCs events. However it led to large amount of code duplication in event handlers across multiple contexts. For instance, multiple contexts are interested in daily stocks of SKU.
So we make every BC to have its own read model that is responsible for building projections based only on its events and UI read model that collects all events necessary for ui. Is it right approach?
Thanks