10 When hexagons talk: Integration modes and the external architecture
This chapter explains how a hexagon fits into a larger system by making every external interaction explicit. Using WriteFlow and its partners, it shows that the boundary is where direction, meaning, timing, and ownership become visible: an outside system may drive WriteFlow with a request, WriteFlow may drive another system, or a coordinator may manage a longer process that spans several systems. The key idea is to treat these choices as design decisions made by the team, not as details hidden inside the domain model, and to record them clearly so the architecture can evolve safely.
The text distinguishes inbound from outbound integration, then separates requests from facts. A request asks for work or information and may require an immediate answer, while a fact reports that something has already happened and can be published for others to react to later. From there, the chapter presents three integration modes: synchronous calls, event-driven integration, and external orchestration. Synchronous calls are simple but create time coupling; events support loose coupling and eventual consistency but require tolerance for duplicates and reordering; orchestration is needed when a multi-step process must survive failures, with a durable coordinator owning sequencing, retries, and compensation.
Across all modes, the same rules hold: the domain decides what is allowed, the application layer decides what leaves the hexagon, and adapters alone know the external systems and protocols. The chapter concludes by mapping these decisions into a contract map, where each neighbor gets one line describing direction, intent, mode, and contract ownership. That map clarifies which contracts WriteFlow owns and which it consumes, helps teams avoid mixing responsibilities, and provides a practical artifact that should be created before implementation and updated whenever contracts change.
The decisions for one interaction produce one contract-map entry. Here, the CMS’s request is inbound, synchronous because the CMS needs WriteFlow’s decision before continuing, and governed by a contract WriteFlow owns.
Internal orchestration keeps the sequence inside one transaction. External orchestration spans services, so a coordinator holds the sequence durably and runs compensation when a later step fails.
Example of a potential external architecture as a contract map for WriteFlow. Every neighbor becomes one line that records a direction, a mode, and an owner. Draw your own the same way; the neighbors change, the four questions do not.
Summary
- Integration grows the edge of the hexagon, not its core. A new external system means a new adapter, not a new domain rule.
- Direction is the first decision at any boundary. Inbound, the external system starts and is a driving actor; outbound, the hexagon starts, and the other system is a driven actor. Direction belongs to the interaction, not to the system.
- Every message carries one of two intents. A request asks for work and expects an answer; a fact reports what happened and expects none. Either intent can travel in either direction.
- There are three integration modes: a synchronous call, an event, and external orchestration. In a synchronous call, the caller waits; with an event, the publisher hands off a fact and continues; with external orchestration, a coordinator tracks the sequence across steps.
- Internal orchestration is not one of the modes. A sequence that stays in one process and one transaction is the handler's own job. External orchestration is for a process that crosses services, outlives a request, or has to compensate a committed step, and it exists because distributed systems do not give atomicity across services for free.
- Choose the mode from the interaction's consistency and time needs. A synchronous call when the next step needs the answer, an event when you only inform, a coordinator when the process must survive failure.
- The same ownership rules hold in every mode. The domain decides what is allowed, the application layer decides what leaves, and the adapter is the only part that knows the other system. The correlation ID travels in an opaque envelope the core never opens.
- Draw the contract map before you write the adapter. Separate the contracts you own from the ones you consume, and version the ones you own, because other teams depend on them.
Clean Applications with Hexagonal Architecture ebook for free