Hexagonal architecture - Another way to the hexagone
The content here is under the Attribution 4.0 International (CC BY 4.0) license
I am not sure how this post is going to be, but the idea is to brain-dump what is my current understanding of hexagonal architecture and try to make a journal of that
As I improve my understanding I can improve this post and so on.
NOTE 1:Hexagonal architecture is usually mixed with clean architecture, even though, it was used as an inspiration for the clean architecture, they are different. Valentina Cupác describes that in her talk with details(https://www.youtube.com/watch?v=IZWLnn2fNko).
NOTE 2: I found something that seems wrong and would like to contribute. Leave a comment and I can reply as fast as possible.
Hexagonal
I got to know hex architecture(I am going to follow this pattern from now on to refer to the hexagonal architecture) in the clean architecture book, indeed it was inspired by Uncle Bob to get the clean architecture in place.
Alistair Cockburn realized that there was a different approach to building applications instead of the classical layered architecture:
The attempted solution, repeated in many organizations, is to create a new layer in the architecture, with the promise that this time, really and truly, no business logic will be put into the new layer.
A more flexible way of dealing with different adapters in the application and using the same code to process business rules. Even though experts argue that there are differences between open and closed layers, to avoid such interactions or constraint violations, in the hex architecture the approach is different stating that the goal is to avoid it by design instead of trying to enforce a constraint.
Nevertheless, [1] says that hexagonal architecture is an example of a layered architecture as it conforms to all the constraints and properties of a layered architecture.
Another way to the hexagone
Definition
Hexagonal architecture is defined in different aspects. Aspects are something that created to define this architectural style as I believe they are the key:
- ports, as the author describes “The term “port and adapters” picks up the ‘’purposes’’ of the parts of the drawing. A port identifies a purposeful conversation”.
- adapters, you might have many adapters for a single port.
In the book Strategic Monoliths and Microservices [2] Vaughn Vernon and Tomasz Jaskula also used a similar definition, on the other hand, what caught my attention to their definition is the way used to differentiate the layered architecture from hexagonal.
What are the disadvantages of hexagonal architecture?
At first, the hexagonal architecture seems to be a magical approach that will automagically give testability to any application, at least this is what some of the articles on the web sells the hexagonal architecture.
Nevertheless, some of the implications that come when adopting hexagonal architecture are:
- The developer experience: as the implementation of hexagonal architecture depends on interpretation, it varies based on the programming language and the years of experience of the developer writing the code. Hexagonal architecture usually is not the first style that one starts with. It is MVC that comes embedded in different frameworks.
- The understanding of the developer on the libraries and the frameworks being used: the different ecosystems of different programming languages bring challenges as they offer a pre-created structure of how the problem should be solved. Understanding each piece of them is key to creating abstraction to create the inside and the outside of the hexagon. For example, Davi Vieira shared his opinions on implementing hexagonal architecture with Java in a book [3].
- Other architectural styles are also testable: other styles are posed as “not testable” or that are difficult to test, regardless, frameworks are set to use the famous Model-View-Controller.
Being said that the shift using hex architecture is mostly due to the developer experience at hand. Having experience, the other points mentioned will degrade their impact.
Related subjects
- Gordon Skinner - Hexagonal Architecture in DDD
- Implementing Domain-Driven-Design by Vaughn Vernon - Chapter 4.
References
- [1]J. Stenber, “Exploring the Hexagonal Architecture,” 2014 [Online]. Available at: https://www.infoq.com/news/2014/10/exploring-hexagonal-architecture. [Accessed: 15-Apr-2022]
- [2]T. J. Vaughn Vernon, Strategic Monoliths and Microservices. The Addison-Wesley Signature Series, 2021.
- [3]D. Vieira, Designing Hexagonal Architecture with Java: An architect’s guide to building maintainable and change-tolerant applications with Java and Quarkus. Packt Publishing, 2021.
Table of contents
Got a question?
If you have question or feedback, don't think twice and click here to leave a comment. Just want to support me? Buy me a coffee!