0
votes

I have an example similar to what is described here:

An entity’s identity can cross multiple microservices or Bounded Contexts.

The same identity (that is, the same Id value, although perhaps not the same domain entity) can be modeled across multiple Bounded Contexts or microservices. However, that does not imply that the same entity, with the same attributes and logic would be implemented in multiple Bounded Contexts. Instead, entities in each Bounded Context limit their attributes and behaviors to those required in that Bounded Context’s domain.

For instance, the buyer entity might have most of a person’s attributes that are defined in the user entity in the profile or identity microservice, including the identity. But the buyer entity in the ordering microservice might have fewer attributes, because only certain buyer data is related to the order process. The context of each microservice or Bounded Context impacts its domain model.

In my case, I have a Subscription model that two different bounded contexts that have their own attributes.

Going a step further, a Subscription belongs to an Agency, and an Agency can only have one (not 0, not many) Subscriptions.

So based on this, I've been thinking what the aggregate id will be. As a Subscription has a 1-1 mapping with an Agency, is it OK to use the same ID as the Agency?

I think this makes sense as a Subscription doesn't need it's own ID. Even if it did I don't think it would be returned to the user, the user can reference it through the owning Agency id.

In this bounded context the Agency aggregate (or it's attributes) are not relevant so I don't believe they are part of the same aggregate.

To sum up, is it OK for an aggregate to share the ID of another aggregate if it is a 1-1 mapping?

1
Clarification questions. If Subscription can only be referenced through the owning Agency, should it even be considered an Aggregate? Is Agency as a concept present in both the Bounded Contexts, along with Subscription? What happens to the Subscription when the Agency is archived/deleted? Are you using an RDBMS for persistence or a document store? Is the mechanism of using different primary IDs and linking to Agency through an agency_id attribute an option?Subhash

1 Answers

0
votes

I don't think that the actual implementation w.r.t. the Id really matters. It should be perfectly fine to share an identifier.

This is somewhat different from "splitting an aggregate across" BCs which is something you most certainly would not want to do :)

An aggregate in one BC would be represented either by an id or as a value object in another BC. Only a single BC should be the system of record of any aggregate.