Domain-Driven Design: Context Mapping, how to design relationships between Bounded Contexts.
Learn to build a Context Map and choose how models and teams collaborate. Compare eight integration patterns, distinguish Upstream and Downstream, and apply a brief TypeScript ACL without introducing microservices.
The indicator keeps the furthest percentage explored; marking the article complete is your choice.
The API works, but teams remain blocked
The Sales team needs to know whether it can reserve two backpacks. Inventory offers an API that responds correctly, but its contract changes without notice. Billing, meanwhile, interprets “confirmed order” as “order ready for invoicing,” while Sales also confirms operations whose invoicing requires a later review.
Calls return valid responses. The problem lies in agreements: who decides what data mean, who can request changes, and who must adapt when the other model evolves.
We already know a Bounded Context delimits a coherent model. Now we will design relationships between those models. We will use Catalog, Sales, Inventory, and Billing, initially as contexts within a modular monolith. We need not distribute the application to discover that teams and contracts depend on one another.
What a Context Map represents
A Context Map documents the contexts participating in a system and the relevant relationships between them. Context Mapping is the work of discovering, discussing, and maintaining those relationships.
The map should help answer concrete questions: who does Sales depend on to interpret an offer, who negotiates the reservation contract, where is Sales language translated into Billing language, and which part of the model is deliberately shared?
Eric Evans describes the Context Map as a representation of contexts and their contact points, including translations and exchange agreements. His reference also includes patterns expressing relationships between teams. DDD Reference, Context Map and relationship patterns.
Distinguish two map versions:
Current: reflects existing dependencies and agreements, even uncomfortable ones.
Target: describes proposed changes, with owners and steps to reach them.
Drawing an ideal collaborative relationship where nobody negotiates changes today conceals the risk you need to manage.
It is not an infrastructure diagram
“Sales calls Inventory through HTTP” describes a mechanism. It does not yet say who controls the contract, what reserving means, or how an incompatible change is agreed.
An infrastructure diagram can show servers and networks. A sequence diagram can order requests. The Context Map incorporates different information: model dependencies, translation, responsibilities, and coordination capacity.
You can reference those other diagrams without drawing all their details inside the map.
Upstream and Downstream: dependency, not a request's path
In an asymmetric relationship, Upstream is the side whose model or decisions constrain the other. Downstream is the side depending on them and needing to consider their evolution.
Suppose Inventory defines a reservation's public states and rules. Sales consumes that contract. For that relationship:
This article's legend: U means Upstream, D means Downstream, and the arrow points toward the dependent context. It represents neither the direction of an HTTP request nor the business's temporal sequence.
Although Sales sends the request and receives the response, it remains Downstream relative to Inventory's offered contract. An HTTP server is not Upstream by definition: examine semantic dependency and who constrains changes.
Furthermore:
A context may be Upstream in one relationship and Downstream in another.
Downstream does not mean less business importance.
The provider may need to address consumer needs through explicit agreements.
Two models with reciprocal needs should not receive asymmetric labels for convenience.
If every change requires negotiation in both directions, investigate whether there is symmetric collaboration, two different relationships, or a separation that is not yet well defined.
Eight patterns for choosing a relationship
The following patterns belong to Evans's Context Mapping vocabulary. Their descriptions here are adapted, and examples are instructional decisions, not a universal e-commerce map. The original reference provides their formulations and nuances. Eric Evans: DDD Reference, pages 30–37 of the document.
1. Partnership: coordinate because the result depends on both
Two teams agree to work as partners when their deliveries need one another. They coordinate planning, integration, and changes so both can succeed.
Imagine Sales and Inventory jointly launching a new reservation mode for advance sales. Neither can deliver the capability separately, and both can commit to the same goal.
Provides: direct communication and joint decisions for changes affecting both.
Costs: sustained coordination. If one team cannot make that commitment, writing Partnership on the map does not create it.
It does not require sharing all classes or one schedule for every task. It does require real agreements about the collaboration sustaining that feature.
2. Shared Kernel: share little and govern it together
Teams agree to share a small part of the model, together with code or elements necessary to keep it consistent. Changes require coordination.
On a booking platform, two contexts could share a carefully agreed definition of time interval. Before doing so, they must check that both interpret its endpoints, time zone, and relevant rules identically.
Provides: avoids repeatedly translating a part that truly has the same meaning.
Costs: introduces an area of joint change. The kernel stops being small if it ends up containing complete entities, specific rules, and unrelated utilities.
A logging package is not a domain Shared Kernel. Neither is a library one team imposes unilaterally. In our main example, we will choose contracts and translation, without importing internal models between contexts.
There is an asymmetric dependency, but the Upstream team incorporates Downstream needs into its planning. “Customer” here describes the consuming team's role, not the store's buyer.
Inventory offers reservations, and Sales needs to distinguish an accepted reservation from a rejected one. Both agree on states, delivery dates, and acceptance tests.
Provides: explicit consumer influence and verifiable provider commitments.
Costs: requires time, negotiated priorities, and delivery capacity. It does not mean Sales has veto power over every internal Inventory change.
An occasional meeting or available endpoint does not demonstrate this relationship exists.
4. Conformist: adopt the offered model
Downstream accepts Upstream's model and avoids maintaining substantial translation of its own. It is an option when it cannot influence the provider and adapting to its language is manageable.
A small portal reproducing carrier tracking may decide to use states as offered if that language serves its purpose.
Provides: less translation effort and a simpler beginning.
Costs: provider evolution constrains the consumer. If the local business begins needing a different meaning, initial convenience may become expensive coupling.
Conforming to the model does not mean blindly trusting responses: validation and security remain necessary.
5. Anti-Corruption Layer: protect the consuming model
An Anti-Corruption Layer, or ACL, translates interaction with an external system into the language the consuming context needs. It can be small; it requires neither another service nor an integration platform.
If Billing needs “units reserved for this order” while Inventory speaks of allocations with its own codes, Billing can maintain a translation at its boundary.
Provides: prevents those codes and assumptions from spreading through the local model.
Costs: translation must be maintained and meaning changes detected. An ACL does not eliminate provider dependency or invent capabilities the provider lacks.
A wrapper merely renaming a function while returning the entire external model may leave the problem intact.
6. Open Host Service: offer stable integration to multiple consumers
Upstream offers a public integration protocol serving multiple consumers' needs instead of creating a particular connection for each one.
Inventory could expose query and reservation capabilities to Sales, warehouse operations, and other authorized consumers.
Provides: a maintained, understandable integration point.
Costs: the provider takes on protocol compatibility, documentation, and evolution. Designing for multiple consumers requires preventing the contract from becoming the sum of all their particularities.
“Open” does not mean anonymous or free access. An Open Host Service may require authentication, authorization, and usage restrictions.
7. Published Language: agree on interpreting exchanges
A Published Language defines a documented language for expressing shared information. It includes meaning, not just format.
For example, a sale confirmation identifies the order, accepted terms, currency, and relevant moment, with explicit interpretation rules.
Provides: a common exchange vocabulary without requiring a single internal model.
Costs: requires governing evolution and clarifying ambiguities. Valid JSON does not itself explain whether an amount includes taxes or whether “confirmed” permits issuing an invoice.
It can accompany an Open Host Service. They are not synonyms: one describes the integration offering, the other the exchanged language.
8. Separate Ways: decide integration is not worthwhile
Two contexts go their separate ways when integration's benefits do not justify its cost.
An educational site may keep its workshop booking tool independent of a public article library. If no business need connects them, there is no need to synchronize users or categories merely because both use “topic.”
Provides: autonomy and fewer dependencies.
Costs: consciously accepted duplication or manual tasks may remain.
If someone exports and imports files to connect the processes, document that dependency. Do not turn it into Separate Ways solely because there are no HTTP calls.
Patterns describe aspects that can be combined
Do not choose one pattern for the entire application.
Inventory can offer an Open Host Service with a Published Language. Sales can negotiate requirements through Customer/Supplier while retaining its ACL to protect its vocabulary.
Each decision answers a different question:
Coordination: do teams commit as partners or negotiate an asymmetric relationship?
Model: do they share a part, adopt the external model, or translate it?
Integration offering: is there a maintained public service?
Exchange language: are semantics documented?
Need: should these contexts be connected?
Do not confuse combining compatible aspects with labeling a relationship with everything. For the same scope, fully adopting a model and protecting a different model through translation are different decisions.
Build the store's map step by step
1. Record current dependencies
We start from this hypothetical situation:
Sales reads commercial descriptions from Catalog.
Sales requests reservations from Inventory.
Billing uses confirmed terms from Sales.
Catalog needs no Billing data.
We still need to discover whether teams negotiate changes and how they interpret those data.
2. Ask who controls each agreement
Catalog maintains a presentation contract Sales considers sufficient. Inventory can negotiate reservation needs. Sales agrees with Billing on what a billable sale means.
OHS abbreviates Open Host Service; PL, Published Language. These abbreviations are declared for this article, not mandatory notation. Arrows retain the previously defined direction of dependency.
In Catalog–Sales, Conformist is limited to consumed presentation data. Sales retains its own business rules; it does not automatically adopt the entire catalog model.
3. Justify a relationship in a record
For Inventory–Sales:
Need: Sales must know whether a reservation was accepted for the requested order. Upstream: Inventory, responsible for the reservation contract. Downstream: Sales, responsible for interpreting the result in its commercial process. Coordination: Customer/Supplier; agreed needs enter Inventory's planning. Protection: Sales ACL converting external codes into local results. Evolution: notify incompatible changes and verify contract acceptance examples. Outside the agreement: Sales does not decide how Inventory distributes units among locations.
Now teams have something to review. The diagram alone does not show all these commitments.
4. Walk through a concrete change
Inventory wants to add “pending review.” If Sales understands only accepted or rejected, it cannot convert the new state into accepted by default.
The Customer/Supplier relationship enables negotiating semantics and timing. The ACL concentrates adaptation. The contract and its tests must reflect the new decision before use.
The expected observable result is that Sales retains an explicit interpretation. We are not claiming an ACL automatically makes every change compatible.
A brief TypeScript ACL
This instructional example shows translation only. It implements no HTTP, persistence, or real reservation. Sales's HTTP adapter would receive unknown data, check the format, then call this function with the validated type.
// Representación del proveedor, localizada en el adaptador de Sales.// No se importa una entidad interna de Inventory.interfaceInventoryReservationReply {
readonlyreservation_id: string;
readonlyorder_reference: string;
readonlyresult_code: "ALLOCATED" | "DENIED";
}
typeSalesReservation =
| { readonlystatus: "accepted"; readonlyreservationId: string }
| { readonlystatus: "rejected" };
functiontranslateReservation(reply: InventoryReservationReply,
expectedOrderId: string,
): SalesReservation {
if (reply.order_reference !== expectedOrderId) {
thrownewError("La reserva pertenece a otro pedido");
}
switch (reply.result_code) {
case"ALLOCATED":
if (reply.reservation_id.trim().length === 0) {
thrownewError("Falta la referencia de la reserva aceptada");
}
return {
status: "accepted",
reservationId: reply.reservation_id,
};
case"DENIED":
return { status: "rejected" };
default:
thrownewError("Estado de reserva no soportado");
}
}
The translation expresses this example's agreement: ALLOCATED means an accepted reservation, not shipped goods. If Inventory uses that code for a provisional allocation, the agreement would be incorrect even if the code compiled.
The TypeScript type does not validate JSON received over the network. The adapter must reject invalid fields, unknown states, and responses unrelated to the requested operation. The default case reinforces an explicit response to unexpected values but does not replace that validation.
We can describe three behaviors through assertions. This block complements the previous one and uses no external dependencies:
functionassertCondition(condition: boolean, message: string): void {
if (!condition) thrownewError(message);
}
const accepted = translateReservation({
reservation_id: "reservation-20",
order_reference: "order-100",
result_code: "ALLOCATED",
}, "order-100");
assertCondition(
accepted.status === "accepted" &&
accepted.reservationId === "reservation-20",
"Debe conservar la referencia de una reserva aceptada",
);
const rejected = translateReservation({
reservation_id: "",
order_reference: "order-100",
result_code: "DENIED",
}, "order-100");
assertCondition(
rejected.status === "rejected",
"Una denegación no debe convertirse en aceptación",
);
let wrongOrderRejected = false;
try {
translateReservation({
reservation_id: "reservation-21",
order_reference: "order-999",
result_code: "ALLOCATED",
}, "order-100");
} catch {
wrongOrderRejected = true;
}
assertCondition(
wrongOrderRejected,
"Debe rechazar una respuesta perteneciente a otro pedido",
);
These checks protect local interpretation and operation identity. They do not test provider availability or compatibility with its real API. Contract and adapter tests are needed for that.
The ACL belongs to the consumer. It does not authorize Sales to write Inventory tables directly. And if integration uses HTTP, the call does not automatically form part of a local Sales transaction.
An event also needs a documented relationship
Sales can offer Billing an integration contract based on a confirmed sale. The mechanism could be a notification or query; the map must explain dependency and meaning independently of transport.
An internal Domain Event does not become a Published Language by being serialized. Shared information must be selected, its terms documented, and its evolution agreed.
If Billing requires additional conditions to issue a document, its model must retain that decision. The Sales event's name should not silently impose a tax or administrative rule Sales does not know.
Two decisions outside e-commerce
Education: deliberately share a small part
Enrollment and academic planning use a date interval with the same meaning and need to evolve it together. A Shared Kernel may be reasonable if both teams accept its governance and its scope stays small.
The decisive check is semantic: if planning needs open intervals while enrollment works with inclusive deadlines, perhaps they do not share the same concept. Translation may then be clearer.
This example teaches us not to share a class merely because its properties match.
Logistics: accept an external model or translate it
An informational dashboard shows carrier states without adding rules. It can adopt a Conformist approach and reduce integration work.
A customer-service system, however, decides whether a delivery enables a claim. It should not confuse “incident recorded” with “loss confirmed.” An ACL helps separate the carrier's language from those local decisions.
The difference is not the provider: it is the consumer's needs and responsibilities.
Use the map to guide AI
A map is useful for Cursor, Claude, or Codex when accompanied by verifiable agreements. A drawing without a legend or distinction between current and proposed situations can provoke incorrect recommendations.
Three possible prompts:
To discover relationships:
Using these Catalog, Sales, Inventory, and Billing records and interaction examples, build a current Context Map. Identify U/D by model dependency, not HTTP direction. Separate facts from hypotheses. Return a legend, relationships, and open questions; do not invent agreements between teams.
To propose a change:
Sales consumes Inventory reservations through Customer/Supplier and an HTTP ACL owned by Sales. Propose incorporating a new pending state without treating it as accepted. Retain consumer contracts and do not import Inventory entities. Deliver minimal contract changes, translation, and test cases; do not add infrastructure.
To review code:
Compare this diff with the attached map. Look for cross-context imports, exposed internal models, accidental adoption of external codes, and incompatible changes. Explain affected behavior and distinguish agreement violations from design preferences.
A person must check that the described agreements exist and that examples reflect business semantics. AI can detect inconsistencies; it cannot negotiate real commitments for teams.
Exercises for choosing relationships
1. The provider that does not negotiate
An external provider offers a fixed returns model. Your system needs to distinguish a requested return from an approved refund. Is marking Customer/Supplier enough?
2. The shared library
Two teams share a thirty-field Customer class. Every change breaks the other. They propose calling it Shared Kernel and continuing unchanged. What would you review?
3. Reservation arrows
Sales sends requests to Inventory. A diagram marks Sales as Upstream because it initiates communication. Inventory decides the contract, and Sales adapts its results. How would you correct the map?
Reasoned solutions
1. No. Customer/Supplier requires incorporating consumer needs into the provider's planning. If that does not happen, I would document the actual dependency. Since local meanings matter, I would propose an ACL that does not confuse states; if the provider offers insufficient information, that must remain an explicit limitation.
2. The name creates neither joint governance nor semantic consistency. I would review which concepts truly share meaning, the minimal part they need to share, and how changes are coordinated. If rules differ, I would separate models and define a contract instead of expanding the global entity.
3. For that relationship, Inventory is Upstream and Sales Downstream. The dependency arrow can point from Inventory to Sales, with an explicit legend. If request and response must be shown, I would use a separate sequence diagram. Then I would document whether Sales negotiates requirements, conforms, or translates the model.
Keep the map useful
Review the map when a contract changes, a consumer appears, or responsibility for integration decisions changes. It need not be updated for every internal change that does not affect the relationship.
Before accepting a relationship, check three things: you can explain the dependency, the responsible team recognizes the agreement, and an example shows how the contract is interpreted.
A small map with honest relationships lets you decide what to negotiate, translate, and leave independent. It can serve the same modular monolith for years; server count does not determine its usefulness.
Integrate the collection by building an order API with TypeScript, Express, Zod, and SQLite. Includes project files, domain rules, events, version control, Vitest tests, and commands to run and verify it locally.
Learn to guide AI agents with business rules, context boundaries, and verifiable criteria. A TypeScript case shows how to prepare instructions, protect Order, design tests, and review changes without delegating architectural judgment.
Compare a modular monolith with separating Sales, Payments, and Inventory. Design contracts in TypeScript and Express and understand partial failures, eventual consistency, idempotency, Outbox, and Sagas without introducing complex infrastructure.