ismaelcabanas
ismaelcabanas

Reputation: 104

Modeling aggregates

I have the following requirements:

Well, in this situation, you would create an aggregate for article, other for question and other for answer.

If yes, how to keep the invariant that an article have between 1 and 3 questions?

If no, how would you model it?

Thanks a lot!

Upvotes: 0

Views: 35

Answers (1)

Levi Ramsey
Levi Ramsey

Reputation: 20551

  • Article aggregate includes a set of references to Question (via an aggregate root, e.g. the question ID)
  • An attempt to add a reference to a Question fails if there are already 3 references for that Article

Since an aggregate defines a consistency boundary, publishing an article is a saga. Adding a question is likewise going to be a saga if you want the Question to track which Article(s) it's associated with (you didn't directly say that Question maintains an invariant that it's only ever associated with one article).

Upvotes: 1

Related Questions