Hi @fcastells,
let me quote here a portion of the original question
All implementations I’ve seen of similar systems contain a single Order model, which tends to be really bloated with information about the products, the provider, the consumer, invoicing, deliveries, payments, etc. I am trying to avoid that, but I am facing the question of “Who owns the order”?
-
There is an Orders bounded context which is accessed by both the consumer and the provider. This means that the consumer api has a Place Order operation that talks to the Orders BC and creates an order and the Providers Api has an operation like Accept Order which talks to the same Orders BC and changes the status of that same order model.
-
There are 2 Orders BCs: Consumer Orders and Provider Orders. The Consumer API places an order in the Consumer BC. This creates the order and publishes a ConsumerOrderCreatedEvent. The ProviderOrders BC listens to that event an creates a local Order (ProviderOrder) which references the ConsumerOrder. Through the Provider API the order can be accepted, which will publish a ProviderOrderAcceptedEvent, which will allow the ConsumerOrders to mark the order as accepted and notify the consumer about it.
[/quote]
the key aspect IMO is the following (emphasis mine):
All implementations I’ve seen of similar systems contain a single Order model, which tends to be really bloated with information about the products, the provider, the consumer, invoicing, deliveries, payments, etc. I am trying to avoid that, but I am facing the question of “Who owns the order”?
The fact itself that the order is bloated with to many information, clearly owned by other services, is a sign that the first problem you need to look at is the Order model
. It’s probably too big, with too many responsibilities.
From the logical point of view we can probably identify an Order
owner, let’s say that it’s called Sales
.
Now as you state in your scenario there is the need to identify one or more providers, that will accept and fulfill the Order
, does Sales
own the providers information? probably the answer is no. A Provider Registry
service is a better fit.
Same reasoning applies for customers information on the order, Sales
doesn’t own any customer information, a Customer Registry
service owns those information.
Same goes for all other information you mentioned above. We could probably go as far to saying there won’t be any product information on the order itself, Warehouse
owns products information, not the order.
So which data will we put into the Order
? IDs, just IDs. The Order
will contain the customer ID and provider(s) ID(s), Products IDs, Shipping Information IDs, etc.
ViewModel Composition techniques will be applied so that when displaying the order it’ll appear like information are all stored in the same place, even if that’s not the case.
You can read more about ViewModel composition here: https://particular.net/blog/secret-of-better-ui-composition
There is a full working sample available in the SOA Done right workshop repo.
.m