Every domain eventually runs into this. A business operation needs to maintain invariants between two or more entities on a given model. How can accomplish it without messing the model? Which component should be responsible for ensuring that?

For example, let’s say your domain has members and stories written by them and each profile should display the number of stories published by the member. The team decides to add a “storiesWrittenCount” to the Member Entity to avoid an extra query to the Story Collection.

A naive first attempt to satisfy that scenario would be:

WriteStoryUseCase(story, member) { storyRepo.create(story) member.storiesWrittenCount++ memberRepo.update(member)…

Fernando Martin

15 years of experience in Software Development. Passionate about delivering software at scale and increasing the effectiveness of Engineering teams.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store