How I use Hexagonal Architecture (Ports and Adapters) in Java Spring Boot systems — from Betfair trading frameworks to DWP Digital's benefit platform. Practical patterns for keeping domain logic clean and independently testable.
Working on long-lived, high-stakes systems — from real-time financial data pipelines at Mosaic Smart Data to government benefit services at DWP Digital — I’ve learned that most architectural pain doesn’t come from business complexity, but from tight coupling. Early in my career, I built systems where domain logic leaked everywhere: into controllers, repositories, message handlers, and frameworks. They worked — until requirements changed.
That experience is why Hexagonal Architecture (also known as Ports and Adapters) has become my default approach for building systems that stay maintainable and continue to evolve without fear.
Hexagonal Architecture is a design approach that places your domain logic at the centre of the system and treats everything else—databases, messaging systems, HTTP APIs, frameworks—as replaceable details.
At a high level:
The key idea is simple but powerful:
Your business logic should not depend on infrastructure.
Infrastructure should depend on your business logic.
This inversion is what keeps systems flexible under real-world pressure.
On modern platforms—especially event-driven ones—you rarely have a single interface. A service might be triggered by HTTP requests, Kafka events, scheduled jobs, or batch reprocessing. Without a clear boundary, logic gets duplicated or embedded in the wrong places. Hexagonal Architecture gives you one place where business decisions live, regardless of how the system is driven.
Ports are interfaces owned by the domain:
public interface ClaimRepository {
Optional<Claim> findById(ClaimId id);
void save(Claim claim);
}
Adapters translate infrastructure concerns into domain interactions, keeping frameworks out of the core.
Because the domain depends only on ports, business logic can be tested without Spring, Kafka, or databases. This leads to faster tests, clearer intent, and far greater confidence when making changes.
Hexagonal Architecture isn’t about purity — it’s about protecting what matters most: your business logic. If you’re building systems that must evolve safely over time, it’s one of the most effective architectural patterns you can adopt.