Is CQRS correct for my domain?

一世执手 提交于 2019-12-12 14:50:02

问题


I am modelling an archive which is part of an video demand system. Think of the archive like windows explorer where multiple users can create folders, upload videos, restructure folders etc. There are business rules (permissions) which determine if the user is allowed to do the task (i.e. rename folder, move folders, view folders etc).

I have modeled each folder as an aggregate root and moving one folder to another folder appears to affect two aggregate roots.

From what I understand is I should send an event to modify the other aggregate. However what concerns me is if the second folder has also been modified (say deleted or removed from the system) then I need to send a compensating command to undo the first aggregate change.

I would prefer some sort of transaction that deals with the move (change on both aggregates) together and if it fails then at least I do not need to undo the first part of the move or raise the first part of the event.

This leads me to, is CQRS right for the problem I am trying to solve? And if so could it be that my aggregates are wrong?


回答1:


In DDD the Aggregate should represent the transactional boundary. A transaction that requires the involvement of more than one aggregate is often a sign that either the model should be refined, or the transactional requirements should be reviewed, or both.

This a pure DDD issue and is independent of CQRS or any other architectural pattern.

On the other hand, do you really need to reinvent hierarchical structures like folders containing files? As far as I can tell this has been a solved problem for quite some time. Maybe there's no inherent advantage in formalizing that specific domain once again.

Domain modeling using the patterns of DDD makes most sense in bounded contexts where (1) the domain is very complex and (2) modeling the domain will give your software a real (e.g. competitive) advantage over similar applications. If that specific bounded context is rather simple and/or remodeling it doesn't bring a really great advantage, you are better off using the simplest possible solution.

This represents the IMHO most important concept in Domain-Driven Design, which is Focus on the Core Domain



来源:https://stackoverflow.com/questions/11169097/is-cqrs-correct-for-my-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!