0
votes

I'm finding the answer for a question that how I can keep two bounded contexts eventually consistent, when I am using event sourcing? I mean a situation when I have replicated some values from one context's entity to another context's value object. I know that I can use domain events to get notification, when value is changed, but how to update all those aggregates in my event store, which use those values? It is hard to query aggregate from event store by anything else property than id.

Example:

Identity Context:

  • User (id, username, password, email ) - aggregate root

Discussion Context:

  • Author (id,userame) - value object (these values is from Identity Context)
  • Message (id, content, author ) - aggregate root
1

1 Answers

1
votes

I'm not sure making (AuthorId, username) a Value Object is a good choice here.

  • Username is most likely not a crucial piece of data to have in a Message aggregate. What invariant would that aggregate enforce that is based on username ?

  • You probably have CQRS in place (don't you ?) so a Message's username can be retrieved through a read model rather than in the aggregate itself.

I would create an independent Author aggregate in the Discussion context and have message refer to it only by AuthorId. When an event arrives from Identity, you just have to find the aggregate by AuthorId and do whatever you need to do to it.