Chapter 11: Synchronous boundaries: Anti-corruption layers and distributed read models
This introduction frames the model, availability, and data-ownership challenges of synchronous calls between bounded contexts.
After this chapter you will be able to
- Bounded Context Model Ownership. Explain how bounded contexts differ from team or deployment boundaries, and why a domain remains responsible for its own rules when it needs external facts.
- Synchronous Boundary Protection. Explain how boundary translation protects WriteFlow’s model and how the outbound adapter addresses the availability cost of a synchronous call.
- Cross Context Read Tradeoffs. Distinguish the three ways introduced for reading data another context owns and the tradeoff associated with each.
- Synchronous call directions. Trace the separate author-validation and CMS calls through WriteFlow’s ports and adapters, identifying the driving and driven actors.
- Published contracts and legacy access. Explain why WriteFlow should use a neighbor’s published API and describe the limited legacy-view exception.
- Model leakage prevention. Explain how the inbound and outbound calls prevent another context’s vocabulary from entering WriteFlow’s core.
- Synchronous availability coupling. Explain how the author service’s availability affects WriteFlow’s approval check.
- Translation and domain boundaries. Explain how an anti-corruption layer lets a consuming domain retain its own model and vocabulary while keeping business rules in the domain.
- Consumer-side layer ownership. Describe where the anti-corruption layer belongs in the author-service and CMS calls, and distinguish ordinary input mapping from translating a foreign inbound payload.
- Inbound translation responsibilities. Trace how a CMS request to reopen an article becomes a WriteFlow use case input, distinguishing the CMS’s translation from WriteFlow’s input mapping.
- WriteFlow contract vocabulary. Justify keeping CMS concepts out of WriteFlow’s API, including how to represent a CMS identifier when correlation requires it.
- Outbound response translation. Trace how WriteFlow validates an author through its output port and how the outbound adapter translates the author service’s response.
- Remote failure translation. Explain how the anti-corruption layer translates author-service failures into WriteFlow’s defined errors.
- Translation boundary ownership. Apply the section’s boundary rule to foreign types in inbound CMS data and outbound author-service responses.
- Use Case Timeout Budget. Explain how to choose the author-validation timeout within the use case’s overall waiting budget.
- Read Retry Safety. Explain what a timeout means and when WriteFlow may retry author validation.
- State Changing Retry Guarantees. Describe the conditions for retrying a state-changing call whose outcome is uncertain.
- Circuit Breaker Fast Failure. Explain how a circuit breaker bounds repeated waits when the author service stops responding.
- Degradation and Domain Invariants. Distinguish optional degradation from the required author-validation check and explain how domain rules remain protected.
- Synchronous Dependency Choice. Justify synchronous coupling based on whether the use case needs the answer before it can finish.
- Direct reads from owner. Explain how WriteFlow can ask the author service for a display name and why it would choose that approach.
- Replica contract and upkeep. Describe when WriteFlow might read a replica and what operating that replica requires.
- Query-shaped event projection. Trace how author events produce WriteFlow’s projected author directory and explain its consistency and scope.
- Read strategy selection. Distinguish replicas from projections and explain the practical considerations for choosing between a direct read and a local copy.
- Read data and approval. Explain why the author directory can support display but cannot decide article approval.
- Freshness and source calls. Explain how a query’s freshness requirement determines whether to call the source context or consider a local copy.
- Replica and projection trade-offs. Distinguish when a replica suffices from when a projection is worth considering, including its operational costs.
- Output port strategy selection. Explain how an output port hides the read strategy and how configuration can select an implementation for a specific query.
- Domain rule ownership. Explain why business rules stay out of read models and how the write path handles decisions.
- Synchronous Boundary Responsibilities. Explain how WriteFlow divides decisions and external-system knowledge among the domain, application layer, and adapter during author validation.
- Consumed Model Translation. Describe how each side translates the model it consumes in WriteFlow’s author-service and partner-CMS interactions.
- Owned Read Model Copies. Explain how WriteFlow can answer the display-name query without exposing the author service’s model to its handler or domain.
- API Contract Ownership. Distinguish who owns the author-service and WriteFlow APIs, and explain the resulting responsibilities for adaptation and contract stability.
What it builds on
- Two directions at one boundary (chapter 10) · The boundary between communicating hexagons.
- What an output adapter is (and is not) (chapter 5) · The role of an output adapter at the hexagon boundary.
- Synchronous calls (chapter 10) · Synchronous calls as an integration mode.
- What an input adapter is (and is not) (chapter 5) · The role of input adapters
- Where transaction boundaries live (chapter 6) · Where transaction boundaries live
- Why mapping exists: The boundary tax (chapter 5) · Why mapping exists at a boundary.
- CQS in practice (chapter 4) · The separation of query and command concerns in CQS.
- Domain events vs. integration events (chapter 6) · Events crossing context boundaries.
Section by section
Introduction
This introduction frames the model, availability, and data-ownership challenges of synchronous calls between bounded contexts.
- Bounded Context Model Ownership: Explain how bounded contexts differ from team or deployment boundaries, and why a domain remains responsible for its own rules when it needs external facts.
Why it matters: Model ownership is distinct from how teams and deployments are organized. - Synchronous Boundary Protection: Explain how boundary translation protects WriteFlow’s model and how the outbound adapter addresses the availability cost of a synchronous call.
Why it matters: A synchronous boundary must protect both the local model and the application from an unbounded wait. - Cross Context Read Tradeoffs: Distinguish the three ways introduced for reading data another context owns and the tradeoff associated with each.
Why it matters: Each way of accessing another context’s data brings a different freshness or availability cost.
Key terms: bounded context, model, invariants, domain, anti-corruption layer, outbound adapter, synchronous call, model boundary, read strategy, replica
11.1 Two hexagons, one call
This section describes synchronous calls between WriteFlow and neighboring contexts, their boundary contracts, and the risks of coupling models, availability, and transactions.
- Synchronous call directions: Trace the separate author-validation and CMS calls through WriteFlow’s ports and adapters, identifying the driving and driven actors.
Why it matters: The direction of a call determines which adapter receives or makes it. - Published contracts and legacy access: Explain why WriteFlow should use a neighbor’s published API and describe the limited legacy-view exception.
Why it matters: A boundary contract protects WriteFlow from becoming dependent on another team’s private database schema. - Model leakage prevention: Explain how the inbound and outbound calls prevent another context’s vocabulary from entering WriteFlow’s core.
Why it matters: Translation at the boundary keeps external models from shaping WriteFlow’s core. - Synchronous availability coupling: Explain how the author service’s availability affects WriteFlow’s approval check.
Why it matters: A synchronous dependency can make a local use case wait on another service. - Local transaction boundary: Explain where the use case’s transaction ends and what that means when it calls external actors.
Why it matters: A local transaction does not make a cross-context interaction one atomic commit. - Owned data query alternatives: Distinguish the separate author-data query from the approval check and name its available read choices.
Why it matters: Reading another context’s data is a separate design choice from validating an author for approval.
Key terms: driving actor, driven actor, input adapter, output port, outbound adapter, published API, read-only contract, output adapter, port DTO, exit plan
11.2 The anti-corruption layer
This section explains how an anti-corruption layer translates foreign models and protects a consuming domain at synchronous boundaries.
- Translation and domain boundaries: Explain how an anti-corruption layer lets a consuming domain retain its own model and vocabulary while keeping business rules in the domain.
Why it matters: Translation lets your domain express its own concepts without taking over a neighbor's model or rules. - Consumer-side layer ownership: Describe where the anti-corruption layer belongs in the author-service and CMS calls, and distinguish ordinary input mapping from translating a foreign inbound payload.
Why it matters: Identifying whose model is being consumed tells you who must protect their domain through translation. - Foreign detail isolation: Explain how the anti-corruption layer shields the core from foreign details and changes.
Why it matters: Containing foreign details reduces the impact of a neighbor's changes on your core model.
Key terms: anti-corruption layer, adapter, domain, business rules, consumer, outbound adapter, input adapter, foreign model, API contract, foreign schema
11.3 Inbound: When the CMS calls WriteFlow
The section explains how a CMS calls WriteFlow using WriteFlow’s own contract while each system handles its side of the translation.
- Inbound translation responsibilities: Trace how a CMS request to reopen an article becomes a WriteFlow use case input, distinguishing the CMS’s translation from WriteFlow’s input mapping.
Why it matters: The boundary stays clear when each system translates its own side of the interaction. - WriteFlow contract vocabulary: Justify keeping CMS concepts out of WriteFlow’s API, including how to represent a CMS identifier when correlation requires it.
Why it matters: Protecting the contract from a partner’s vocabulary reduces coupling to changes in that partner’s model.
Key terms: anti-corruption layer, input adapter, request contract, use case input, SendArticleBackForReviewCommand, contract, vocabulary, external post reference, domain concept, correlation
11.4 Outbound: Translating into the neighbor's model
This section explains how WriteFlow translates an author service’s responses and failures at its outbound boundary and keeps foreign models out of its use cases.
- Outbound response translation: Trace how WriteFlow validates an author through its output port and how the outbound adapter translates the author service’s response.
Why it matters: The handler can work in WriteFlow’s terms without depending on the author service’s response model. - Remote failure translation: Explain how the anti-corruption layer translates author-service failures into WriteFlow’s defined errors.
Why it matters: The handler deals with errors defined in its own context rather than the neighbor’s failures. - Translation boundary ownership: Apply the section’s boundary rule to foreign types in inbound CMS data and outbound author-service responses.
Why it matters: Fixing the responsible boundary keeps foreign types from leaking into commands, queries, and domain objects.
Key terms: output port, outbound adapter, DTO, validateAuthor(authorId), anti-corruption layer, AuthorNotFound, DependencyUnavailable, Error, boundary, contract
11.5 Bounding the availability cost
This section explains how WriteFlow bounds synchronous dependency delays and failures without relaxing domain rules.
- Use Case Timeout Budget: Explain how to choose the author-validation timeout within the use case’s overall waiting budget.
Why it matters: A timeout keeps a slow neighbor from consuming more time than the use case can afford. - Read Retry Safety: Explain what a timeout means and when WriteFlow may retry author validation.
Why it matters: Distinguishing an unanswered call from a definitive refusal prevents unsafe or pointless retries. - State Changing Retry Guarantees: Describe the conditions for retrying a state-changing call whose outcome is uncertain.
Why it matters: An apparently failed request may already have changed the neighbor’s state. - Circuit Breaker Fast Failure: Explain how a circuit breaker bounds repeated waits when the author service stops responding.
Why it matters: Failing fast saves the caller’s time and frees threads when repeated attempts are unlikely to help. - Degradation and Domain Invariants: Distinguish optional degradation from the required author-validation check and explain how domain rules remain protected.
Why it matters: An outage must not cause the application to approve something its domain would reject. - Synchronous Dependency Choice: Justify synchronous coupling based on whether the use case needs the answer before it can finish.
Why it matters: The integration choice should reflect the work’s actual dependency rather than the neighbor’s current uptime.
Key terms: timeout, end-to-end deadline, outbound adapter, transient failures, author validation, idempotency, deduplication, retry window, operation-specific status check, circuit breaker
11.6 Reading data another context owns
This section compares ways for WriteFlow to read author data owned by another context while preserving ownership and accounting for freshness, availability, and local-copy costs.
- Direct reads from owner: Explain how WriteFlow can ask the author service for a display name and why it would choose that approach.
Why it matters: This is the simplest way to read another context’s current data without taking on a copy. - Replica contract and upkeep: Describe when WriteFlow might read a replica and what operating that replica requires.
Why it matters: A local copy can keep reads available, but only if its staleness and operational burden are acceptable. - Query-shaped event projection: Trace how author events produce WriteFlow’s projected author directory and explain its consistency and scope.
Why it matters: A query-shaped local view can make reads independent of a live owner call when the query can tolerate lag. - Read strategy selection: Distinguish replicas from projections and explain the practical considerations for choosing between a direct read and a local copy.
Why it matters: Choosing the right read shape avoids both unnecessary remote calls and unnecessary local-copy work. - Read data and approval: Explain why the author directory can support display but cannot decide article approval.
Why it matters: Keeping stale read data out of approval decisions protects the command’s business rules.
Key terms: author service, output port, read API, availability and latency coupling, replica, published contract, read model, rebuild, reconcile, projected view
11.7 Choosing a read strategy
This section explains how to choose and encapsulate a per-query read strategy while preserving source authority and domain rules.
- Freshness and source calls: Explain how a query’s freshness requirement determines whether to call the source context or consider a local copy.
Why it matters: The required freshness determines which trade-offs a query can safely make. - Replica and projection trade-offs: Distinguish when a replica suffices from when a projection is worth considering, including its operational costs.
Why it matters: A projection can reduce request-time work, but it also creates ongoing work and consistency costs. - Output port strategy selection: Explain how an output port hides the read strategy and how configuration can select an implementation for a specific query.
Why it matters: Keeping the choice behind the port lets a query change its data source without rewriting its handler. - Domain rule ownership: Explain why business rules stay out of read models and how the write path handles decisions.
Why it matters: A convenient local view must not become an unowned, potentially stale authority for business decisions. - Read model event caution: State the delivery conditions an eventually consistent view must tolerate.
Why it matters: A local view must remain usable despite the update delivery conditions described here.
Key terms: source context, current value, latency, availability coupling, local copy, replica, projection, response-time target, update processing, lag
11.8 The rules that hold at a synchronous boundary
This section summarizes ownership, translation, and read-model rules at WriteFlow’s synchronous boundaries.
- Synchronous Boundary Responsibilities: Explain how WriteFlow divides decisions and external-system knowledge among the domain, application layer, and adapter during author validation.
Why it matters: These responsibilities keep an external service from taking over WriteFlow’s own decisions. - Consumed Model Translation: Describe how each side translates the model it consumes in WriteFlow’s author-service and partner-CMS interactions.
Why it matters: Explicit translation keeps each system’s model at its own boundary. - Owned Read Model Copies: Explain how WriteFlow can answer the display-name query without exposing the author service’s model to its handler or domain.
Why it matters: This lets WriteFlow retrieve another context’s data without making that context’s model its own. - API Contract Ownership: Distinguish who owns the author-service and WriteFlow APIs, and explain the resulting responsibilities for adaptation and contract stability.
Why it matters: Naming the contract owner and translator makes boundary responsibilities clear.
Key terms: domain, application layer, outbound adapter, output port, port’s DTO, input adapter, command, query, replica, projected view
11.9 Summary
Concepts explained in this chapter
- projectionA projection is a read-only view containing selected data from a domain model rather than the domain entity itself.
- read replicaA copy of data maintained from a source system and used to serve reads.
- driven adapterAn adapter that implements an output port and translates application requests into interactions with an external system.
- anticorruption layerA translation boundary that protects a domain model from the concepts and representations of an external system.
- read modelA model optimized for retrieving and presenting selected application data rather than enforcing domain behavior.
- circuit breaker patternA resilience pattern that temporarily blocks calls to an unresponsive dependency and permits limited probes to determine when it has recovered.
- graceful failureA pattern in which a system returns reduced functionality or results when a dependency is unavailable while preserving required behavior and invariants.
- data mappingData mapping is the transformation of data between representations used by different system components or layers.
- driving adapterA primary adapter translates an external trigger into a call to an application input port.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
