I need some clarification about managing identifiers for entities in DDD.
Assume we have Product model. It can have different meaning in Sales context, Shipping context and Inventory context. So we can have different models for each context according to the DDD.
Assume I'm using Guid as identifiers for entities. When I create a product with a Guid, should It create instances in other two contexts with that same Guid? or should we use different Guid in each contexts?
If we gonna use different Ids in different contexts, how do we know which product in Shipping context relates to product in Sales context? Since we use different Ids in each context how the same product will be identified between different contexts?
You should share the ID within all your bounded contexts. Whether it's their PK or some tracking field. (better to use PK).
Yes, but not all coupling is bad, on the contrary, some would be necessary. But you have to be aware of the
productlifecycle. Who creates, modifies, and deletes it? Do any changes on theproductaffect every bounded context? Have a clear vision about the lifecycle, otherwise, you'll end up in a bad mess.Note: If modifying the
producthas a side effect on the other bounded contexts, then we shared a state across all bounded contexts because:To sum up, duplicating data lowers the coupling but makes the design more complex (keeping all data up-to-date) and brings more issues on validations (are we duplicating the source of truth or not?).