Aggregate root invariant enforcement with application quotas

后端 未结 2 1510
感动是毒
感动是毒 2020-12-21 11:54

The application Im working on needs to enforce the following rules (among others):

  1. We cannot register a new user to the system if the active user quota for the
2条回答
  •  情深已故
    2020-12-21 12:49

    I'm pretty sure that this is a common scenario that must have a better way to be implemented that my previous examples.

    A common search term for this sort of problem: Set Validation.

    If there is some invariant that must always be satisfied for an entire set, then that entire set is going to have to be part of the "same" aggregate.

    Often, the invariant itself is the bit that you want to push on; does the business need this constraint strictly enforced, or is it more appropriate to loosely enforce the constraint and charge a fee when the customer exceeds its contracted limits?

    With multiple sets -- each set needs to be part of an aggregate, but they don't necessarily need to be part of the same aggregate. If there is no invariant that spans multiple sets, then you can have a separate aggregate for each. Two such aggregates may be correlated, sharing the same tenant id.

    It may help to review Mauro Servienti's talk All our aggregates are wrong.

提交回复
热议问题