r/softwarearchitecture • • 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:

  1. What does Hexagonal Architecture offer beyond DIP and event-driven design? Is there a meaningful architectural benefit beyond conventions and terminology?
  2. 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?
  3. 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.

34 Upvotes

19 comments sorted by

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

6

u/damngoodwizard Oct 24 '26

Yeah vertical slices are a prerequisite for a "modulith".

1

u/Pleasant_Chipmunk327 Oct 24 '26

Agree with the statement but I found the book you recommended pretty shallow and it also contains some errors.

I would rather recommend reading „Learning Domain-Driven Design“

3

u/CzyDePL Oct 24 '26

I actually love Khononov's books and teachings, but I don't think it's fair comparison. I see "Get Your Hands Dirty on Clean Architecture" as an opinionated introduction to Hexagonal Architecture, how to actually implement it in a very concrete fashion. As with anything concrete, it won't fit all. But I think it's a good starting point to see what's the fuss about. LDDD is more high level, less immediately-implementable, practical lessons. Although I would recommend going through at least Chapter 10. Design Heuristics before designing anything new to see what are the choices. My point is that recommending going all the way into DDD to someone who is at the level of building applications according to framework tutorials is too big jump

1

u/Ready_Reception8949 Oct 24 '26

Wait do you mean no layers at all, or just layering inside each vertical slice?

1

u/CzyDePL Oct 24 '26

I'm typically going for local decisions so each slice can layer however it wants. As with CQRS, you might want radically different layer structure for your reads versus your writes.

1

u/bigkahuna1uk Oct 24 '26

The primary ports of a hexagonal architecture are essentially driven from events from the adapters. I don’t understand why you say HA is not amenable to event driven design.

The ports in hexagonal are primary in that they react to events sometimes named as driven ports or secondary in that they call out of their domain, sometimes named as driver ports such as calling a repository or publishing an event over some specific transport.

Please elaborate on your statement as it’s goes against my experience of using HA in those sort of situations.

1

u/CzyDePL Oct 24 '26

I've never said HA is not amendable to event-driven, I said it's not related to it, as in "these are orthogonal concerns". You can have all combinations of event-driven / direct calls X layered / hexagonal architecture.

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

  1. Hexagonal architecture is not correlated at all with event driven design. To deal with events exists EDA (event driven architecture). The most important benefit is testability
  2. In my vision hexagonal is the opposite. It split on a technical basis, not for use cases/bounded context/business unita. The best with to structure a module monolith is vertical slice architecture. Every module is a world for is own, but with some exceptions to the rule for things like cross cutting concerns like audits or logging or break the rule and querying cross module if you use the same dB.
  3. The cognitive overhead is low, but there's a lot of boilerplate, but for big projects could be a plus in order to maintain the code base clean in the long run

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.