Is it possible to properly use DDD with all building blocks in monolith application?

306 views Asked by At

I watched some videos, read some blogs about it. SO has many questions and answers on that subject but I can not find anywhere exact answer for my question.

Almost every question and answer has a lack of usage context.

I have one middle sized, asp.net-mvc, monolith application which is running in one process on IIS. I want to (refactor and) go all the way with DDD (and CQRS without separated storage for reads and writes for now) but for me it looks like impossible mission without breaking some rules/guides/etc.

Bounded Context For example I have more than one BCs. Each should not cross their boundaries which means should not share their storage. Right?

It is not possible if you use the whole known (everywhere scattered over the web) solution to work with NHibernate session and UoW.

Aggregate Root Only one AR should be modified in one transaction. When others ARs are involved should introduce eventual consistency (if I remember those are Eric Evans words).

I try to do it but it is not easy in app like that. Pub/Sub not working as desired because if event is published then all subscribers are take their action within one transaction (NSB/MT does that way).

If event handlers wants to modify others ARs they should be executed in separated transactions, right?

Is it possible to deal with it in monolith application (application where whole code works in one process)?

1

There are 1 answers

0
guillaume31 On

It is not possible if you use the whole known (everywhere scattered over the web) solution

[...]

if event is published then all subscribers are take their action within one transaction

I think you're setting yourself useless and harmful constraints by trying to stick to some "state of the art".

Migrating an entire application to DDD + CQRS is a massive undertaking. Some areas of it don't have well-documented beaten paths yet and you'll probably have a fair bit of exploration to do. My best advice would be to stay at a reasonable distance from "the way people do things". Both in traditional ASP.Net web apps because mainstream practices often don't match the way DDD+CQRS works, and in CQRS itself because the case studies out there are few and far between and most probably very domain specific, with a tendency to advocate the use of heavy tools which may not make sense in your context.

You may need to think out of the box, adopt things incrementally and refrain from goldplating everything. You'll be better off starting with very simple implementations that suit your needs exactly than throwing a ton of tools and frameworks at your codebase.

For instance, do you really need a service bus or could a simple Observer pattern suffice ?

Regarding NHibernate, most implementations out there use a (single) Session Per Request approach, but just because it's the most popular doesn't mean it's the only one. Have you tried using multiple ISessions (one for each BC) available at a more programmable level, such as per-action, or managed entirely manually ? Conversely, have you considered sharing a database between Bounded Contexts at first and see for yourself if that's bad or not ?