liveBook · Manning

Hexagonal architecture

As explained in Microservices Patterns, Second Edition

Hexagonal architecture is an architectural pattern that isolates application and domain logic from external systems through ports and adapters.

Hexagonal architecture centers an application on its business logic and connects it to the outside through ports and adapters. The business logic defines ports; adapters handle external requests or carry out external operations. The business logic does not depend on adapters—the adapters depend on it. section 3.3.2

Separate the two directions of interaction:

  • Inbound ports expose business operations. Inbound adapters, such as web controllers or message handlers, invoke those ports; multiple adapters can use the same port. section 3.3.2
  • Outbound ports define how business logic requests external services. Outbound adapters implement those ports, for example through database access objects or remote-service proxies. section 3.3.2

FTGO food ordering

FTGO places Order Management, Delivery Management, Billing, and Payments business logic behind adapters. REST and web interfaces handle inbound requests; outbound adapters connect to MySQL and services such as Stripe and Twilio. The application is logically modular but packaged as a single WAR. section 2.1.1

Figure 3.16 An example of a hexagonal architecture, which consists of the business logic and one or more adapters that communicate with external systems. The business logic has one or more ports. Inbound adapters, which handles requests from external systems, invoke an inbound port. An outbound adapter implements an outbound port and invokes an external system.
Hexagonal architecture

Use the diagram to trace how inbound adapters invoke ports and outbound adapters connect business logic to external systems. section 3.3.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines inbound and outbound ports and adapters, their responsibilities, and the direction of dependency.
Examples
Uses FTGO food ordering, web and REST interfaces, database access, and payment and messaging services.
What you can do after
Understand how to assign responsibilities to ports and adapters and keep business logic independent of adapters.
How it connects
Contrasts with layered architecture and organizes business logic within subdomains and domain views.

Also explained in

Compare how 11 books explain hexagonal architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.