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?
Subscription
can only be referenced through the owningAgency
, should it even be considered anAggregate
? IsAgency
as a concept present in both theBounded Contexts
, along withSubscription
? What happens to theSubscription
when theAgency
is archived/deleted? Are you using an RDBMS for persistence or a document store? Is the mechanism of using different primary IDs and linking toAgency
through anagency_id
attribute an option? – Subhash