Live data from Hacker News

Hexagonal Architecture and Domain Driven Design

towardsdev.com

21–30 of 74 posts

Re: Hexagonal Architecture and Domain Driven Design

#21
The most surprising thing to me about DDD is how bounded contexts (BCs) is a linguistic boundary, and how we talk about things is dependent on where we are in the system. It feels very human, which intrigues me greatly.

To craft a metaphor; the software system is a like Europe and each BC is a country like Spain, France, Italy, and Germany. Each country can be said to have its own culture and language. During trade or tourism, the countries interface in a more limited common language/interaction. But when in Rome, do as the Romans do.

The most thrilling thing for me is seeing how one tests in hexagonal architectures. I am attracted to testing and I really love seeing how folks approach testing. The core (domain) remains the same, but observable side effects come from what you plug in. Want to send an email given some scenario? Plug in the production code. Want to test it? Plug in a module to create test assertions.

Re: Hexagonal Architecture and Domain Driven Design

#22
post #17

There's maybe 20 companies in the world that benefit from this kind of architecture. Everyone else is just being an architecture astronaut or inventing for invention's sake.

you make a good point to keep things simple, "solve the problem you actually have not the one you wished you had". But, many of these ideas can have advantages even in small scale contexts. In some contexts they're not wins (e.g. extreme performance requirements might be prioritised over cost of future change) but in most situations where the cost of abstraction is negligible they're not a bad idea. e.g. i've seen a…

Messes are obviously bad but I dont think these patterns are the answer. They typically balloon the amount of code in exchange for nothing more than a bit of consistency and the ability to write some fairly hollow unit tests.

Hexagonal works where you have a big solid core of complex stateless business logic but thr fact that it's very common to NOT have this and hexagonal presents itself almost as a panacaea makes me hate it a little bit.

Re: Hexagonal Architecture and Domain Driven Design

#23
post #19

While I can get behind hexagonal architecture quite well, the more I use DDD the less I like it. It feels like doing DDD correctly is immensely difficulty, time consuming, makes code harder to read, etc... . While everyone seems to want to do DDD, I've seen so many different approaches to it that always seem to slow down the projects as time moves on, because it becomes a constant struggle with the architecture. And…

There's a book called "Cosmic Python", which gave me a clear basic intro to DDD, though not being a DDD book itself.

https://www.cosmicpython.com/book/chapter_01_domain_model.ht...

> In a nutshell, DDD says that the most important thing about software is that it provides a useful model of a problem. If we get that model right, our software delivers value and makes new things possible.

> If we get the model wrong, it becomes an obstacle to be worked around.

This was painfully true at my last company, and we failed to prioritize naming and modelling. I regret I did not know enough to point out explicitly what was wrong. It could have saved a lot of confusion and on-boarding costs.

I still haven't applied this book fully, but I've certainly taken good ideas from it.

If you want to support it there are many ways to do so: https://www.cosmicpython.com/

Re: Hexagonal Architecture and Domain Driven Design

#24
post #4

can anyone suggest links to reading about DDD & hexagonal architecture that clearly spells out: which context each pattern applies to ; what problem each pattern aspires to solve ; what advantages and disadvantages applying the pattern can have. bonus points for suggesting alternative patterns or linking to case studies / post-mortems / war stories / peer-reviewed empirical software engineering research of how these…

It’s not a book, but I found this talk quite useful to help people grok DDD - “What I talk about when I talk about Domain-Driven Design” https://youtu.be/6nrRfCkeAKU

Re: Hexagonal Architecture and Domain Driven Design

#25
The problem I see is especially in small / mid level companies' contexts, directly trying to jump to DDD usually ends up with a really weird, half-assed implementation. On top of that, it's usually hard to get people up to speed with this kind of architecture. If you're new in the domain, changes take longer as well. You can't go back to the white board every time, re-model your domain and do big changes to it every week.

With classical MVC + Transaction Scripts you can go quite a long way, as boring as it is it can scale up to 500 people working on it. When the time comes, you will have waay more knowledge to your domain and would be able to go with this kind of approach while going towards service oriented architecture or while implementing those boundaries within your monolith like Shopify does.

Otherwise you just waste your time for the things that don't give any benefit to you in short / mid term at all. On the long term nowadays it's really rare people stay at job that long or if that time comes your company will have enough money to throw money into the problem.

Re: Hexagonal Architecture and Domain Driven Design

#26
post #17

There's maybe 20 companies in the world that benefit from this kind of architecture. Everyone else is just being an architecture astronaut or inventing for invention's sake.

you make a good point to keep things simple, "solve the problem you actually have not the one you wished you had". But, many of these ideas can have advantages even in small scale contexts. In some contexts they're not wins (e.g. extreme performance requirements might be prioritised over cost of future change) but in most situations where the cost of abstraction is negligible they're not a bad idea. e.g. i've seen a…

You're a 100% right with that example, I just think it's important to pry these apart as separate issues. The issues you faced should've been solved by a simple data transformation at the system boundary. "Don't let external data formats permeate through your codebase" is, to me at least, basic engineering intuition. There's no deeper meaning to be gleamed from that, the team lead displayed gross incompetence and now you have to clean up his mess.

On the other hand, these "clean architecture" blogs paint this ungrokkable colossus as a northstar -- they contrast it with issues like yours, and present this as the cure to every problem you've ever had in software. I just don't think that's true. None of these blogs ever highlight the loss of understanding. As you approach this style of engineering, you have so many layers, dependency injections and "oh and btw also this" style cross-cuts that no single use-case i.e. codepath can be understood by single person. You're just writing small units of code and hurling them at the codebase, hoping they enter the black hole's orbit and do what you want them to. I like to think that's why Uncle Bob uses huge, unexplorable celestial bodies for book covers :)

P.S. as a counterpoint to your example, I work at a company that's infatuated with the idea of microservices, with little consideration of the tradeoffs involved. A while back I had to add a feature to a new microservice that had been a few months in production. After a couple of weeks of wading through the ports and adapters, DDD-inspired architecture, I realized two things: one, this "service" is just exposing CRUD operations on a single database table with zero business logic in the middle. And two, the Data/ORM adapter layer of the architecture does not work. The migrations are never executed, the DB entities are never mapped, and SQL queryies never fire. Looks like nobody used it since it was first deployed :)

Re: Hexagonal Architecture and Domain Driven Design

#27

The problem I see is especially in small / mid level companies' contexts, directly trying to jump to DDD usually ends up with a really weird, half-assed implementation. On top of that, it's usually hard to get people up to speed with this kind of architecture. If you're new in the domain, changes take longer as well. You can't go back to the white board every time, re-model your domain and do big changes to it every…

The bigger problem I saw wasnt getting people up to speed but:

* The patterns dictated by DDD typically ballooned the amount of code sometimes by up to 4x - usually due to all the added indirection.

* This meant some architectural mistakes took 4x as long to fix. If you misplaced your bounded context borders in particular you were fucked.

* It reduced programming to a bit of a religious exercise where instead of having productive discussions about benefits and trade offs we argued about the "right" way to do DDD.

Re: Hexagonal Architecture and Domain Driven Design

#28
The article and the comments are missing the most important thing.

For DDD don't use SQL as your database.

Postgress ( and eg. The excellent library martendb for dotnet) are perfect for this.

Dump ( or update) your object to the db and the ability to query some properties ( so you don't need an additional search service to query your data - https://martendb.io/documents/indexing/duplicated-fields.htm... )

Using SQL is going to give you a lot of unnecessary headaches when using DDD and trying basic crud.

Re: Hexagonal Architecture and Domain Driven Design

#29
post #14

Earlier quoted context omitted.

non-architect here, what is this blue book you allude to?

"Domain-Driven Design: Tackling Complexity in the Heart of Software" https://www.oreilly.com/library/view/domain-driven-design-ta... There's also "Domain Driven Design, Distilled" providing a comprehensive summary. https://www.pearson.com/us/higher-education/program/Vernon-D...

haha, I know the book but the first one which came to my mind was this :-D http://wiki.squeak.org/squeak/64

Re: Hexagonal Architecture and Domain Driven Design

#30
post #2

I think the underlying principles of DDD and Hexagonal Architecture are sound, but man, they make it so complicated. A good serving of KISS always helps. - Keep your domain models separate from infra implementation stuff - Architect your applications in sensible layers - Decouple stuff that doesn't strictly belong together This stuff should not need lists of XML config to get right, it's portable to any language or f…

Yes, incredible what years of Java Enterprise can inflict to the brain :-). It reminds me of the whole dependency injection circus where in the end it's just the equivalent of passing a function constructing an instance to another function in FP.

except the container can do whatever mumbo-jumbo you may want/need, like declarative transactions, declarative permission checks, logging, publishing events to external systems, etc.

and then you have async constructed dependencies, for example when you need to ask some server for configuration first, before service can be started, and with a good DIC the whole app will just wait automatically and you don't have to worry about any of that anywhere in your app (aka you are abstracted from this)

what you have said is not technically wrong but it also over-simplifies what DI is and it brings to the table

EDIT: that said, I agree in general, that java projects are over-engineered

Post reply on HN