r/softwarearchitecture • u/Ancient-Prize-774 • Oct 24 '26
Discussion/Advice Hexagonal Architecture vs. Pragmatic Layered Architecture in Spring Boot
We're building a multi-tenant platform using Java 21 and Spring Boot as an event-driven modular monolith, with the long-term goal of extracting modules into microservices.
We're evaluating whether to adopt Hexagonal Architecture (Ports and Adapters) or stick with a pragmatic layered architecture using clean interfaces and well-defined module boundaries.
Our original plan was to apply the Dependency Inversion Principle (DIP) through interfaces with multiple implementations (PostgreSQL and in-memory repositories), and use domain events to decouple modules. We're now evaluating whether Hexagonal Architecture offers enough additional value to justify the change.
My personal concern is that Hexagonal Architecture feels less intuitive than traditional layered architecture. Concepts like inbound/outbound ports and adapters, along with the associated package structures, seem to introduce an additional mental model that engineers must learn and navigate. I'm concerned this could make the codebase harder to understand for developers accustomed to conventional Spring Boot structures like controller/, service/, and repository/, without necessarily delivering proportional benefits.
My questions:
- What does Hexagonal Architecture offer beyond DIP and event-driven design? Is there a meaningful architectural benefit beyond conventions and terminology?
- Does it provide tangible benefits when extracting modules from a modular monolith into microservices, or can pragmatic layering with solid boundaries achieve the same result?
- Where does architectural discipline become over-engineering? Do strict port/adapter structures improve maintainability, or introduce unnecessary cognitive overhead and boilerplate in Spring Boot applications?
I'd appreciate practical, production-tested perspectives rather than textbook definitions.
19
u/damngoodwizard Oct 24 '26
What's so complicated in understanding that dependency flow is different from data flow?
While dependency flow becomes:
Caller => Business <= Callee
Data flow remains:
Caller => Business => Callee
With callers possibly being a REST API, a Kafka consumer, a gRPC service, etc... And callees possibly being a database, an external API to consume, a Kafka producer, a mailing service, etc...
That's pretty much all what Hexagonal Architecture is. A layered architecture where the business layer doesn't depend on any other layer. It isn't any more complicated than regular 3 tier architecture with the benefit of being easier to test and evolve.
I really struggle to see how it could be complicated for anyone already familiar with 3-tier and DIP.
22
u/CzyDePL Oct 24 '26
Those are not mutually exclusive, if you combine pragmatic layered architecture with ports and adapters you get clean architecture (not that I like the name or the book, just illustrating the point).
Hexagonal Architecture is not really related to event-driven design that much. And yes, it mainly offers "just" DIP. But it can provide quite a lot of value. I highly recommend reading "Get Your Hands Dirty on Clean Architecture" - it goes through all the benefits of Hexagonal Architecture and how it helps building maintainable software. It's by far the most practical book on the subject I've found.
Also I've never seen modular monolith build as layered application, these are pulling in opposite directions. Modular monolith (if you want to extract into microservices at some point) should package by feature / functionality / vertical slice, you name it. And layered approach bundles together all concerns that will never allow you to split into microservices - you are not doing a "persistence microservice" and anything from business logic layer will be good to grab anything from persistence. Good luck trying to maintain discipline there
5
u/iam-stevie-bee Oct 24 '26
For extraction, what matters is the module boundary, not the port naming. If each module exposes one small interface, publishes events, and nothing reaches into another module's internals, pulling it out later is mostly swaping that interface for a network call. Plain layering can give you that too. What makes it hold is a build test that fails when one module imports another's internals. ArchUnit does this in Java.
3
u/PmMeCuteDogsThanks_ Oct 24 '26
Just build whatever
1
u/bubbles33d Oct 24 '26
Almost every business/web software solves this problem: map JSON to SQL, map SQL back to JSON, or JSON to another JSON. Is just a data mapping and transform exercise.
1
u/bostonaholic Oct 25 '26
They're not really competing. Start layered with clean interfaces inside each module, and only add ports and adapters where you actually have more than one implementation or a boundary you'll extract later (the event bus, external integrations). Hexagonal everywhere in a modulith is a lot of ceremony for code that'll never swap adapters.
1
u/gbrennon Oct 26 '26 edited Oct 26 '26
hex arch(ports and adapter) is really focused in soc bcs u rely on ports(interfaces) and not in adapter (impl)
2. system should be designed with that goal and, in the future, each sub module will become a service. so tem cant have real dependency between modules. u should design how u will distribute events to maintain consistencu in separated modules and to make them really don't understand other concerns
3.. yagni and kiss at its beest.
1
u/chocolateAbuser 21d ago
as many others said, hexagonal and clean or others are not strictly mutually exclusive
the choice of ports adapters is more about how much isolation do you need, how much communication there is between modules and external services, how many teams are working on the project, how many features are anticipated to be in the project, and how fast the project will evolve, as a summary
1
u/PaoloCpc Oct 24 '26
To replay your questions
0
u/zellJun1or Oct 24 '26
After reading multiple books about software architecture, and doing it in practice , I realized they all are very similar, with different terms
Sometimes it depends on the framework you choose , if that framework is developed around a specific architecture terms
You listed controller, service and repository that IS both layered and hexagonal
In the hexagonal context: service is the center, repository and controller are outside connected through ports. Your ports doesn’t have to be named inbound and outbound, doesn’t have to be interface (could as well be function injection)
Following would look good to me as a minimal structure: controller impl, service interface, service impl, repository interface and repository impl
Service interface , is the inbound, while repository interface is the outbound , name it as you like
0
u/pawiusz Oct 25 '26
Hexagonal architecture will not give you any benefits for extracting micro services in the future, because you will not extract all your inbounds into a separate micro service and all your outbounds into another. Instead, you do it for a chosen module - with the full hexagonal architecture inside.
Separation of modules is crucial for any complex project - by making the project way easier to understand, maintain and develop further.
Having said that - inside a single module you can decide if it’s complex enough to introduce hexagonal architecture or it’s rather simple so you won’t benefit from its complexity.
The main benefit of having hexagonal architecture is framework and storage (db) independence of your complex business logic- which makes it easier to design and test.