Lesson 7 of the DDD course · Translating between contexts — especially the ones you don't control · ~30 minutes
Contexts are separate on purpose — but they must exchange facts. Today: the vocabulary for how contexts relate, and deep practice on the one relationship every startup gets burned by.
A context map is exactly what it sounds like: your contexts, drawn, with the relationships between them named. The patterns have deliciously blunt names — and each is a decision about who adapts to whom.[Evans]
| Pattern | Who adapts | When it's right |
|---|---|---|
| Shared kernel | both, on a small joint model | two contexts you control, tightly coupled needs — keep the shared slice tiny |
| Customer–supplier | upstream serves downstream's asks | you control both ends and upstream prioritizes downstream |
| Conformist | you adopt the upstream model as-is | upstream won't change, their model is fine, translation isn't worth it |
| Anti-corruption layer (ACL) | you translate at the boundary | upstream's model is foreign or hostile to yours — most external vendors |
| Published language | both speak a documented common model | many integrations around one standard |
Meridian's map, drawn honestly: ordering is customer–supplier with
billing (both yours); ordering is ACL with BigPay, the
external payment provider (theirs, forever); shipping conforms to the carrier's
label API because translating it isn't worth it. Three relationships, three deliberate choices —
not one accidental tangle.
An anti-corruption
layer is a boundary adapter with one job: foreign concepts enter only after
translation into your model, in exactly one place.[Evans] Without it, watch
what happens: BigPay sends amount as a string of cents and a status enum
("succeeded"); someone stores it raw; a month later Billing types have
fields like bigpay_status; the vendor's vocabulary — their decisions — now
shapes your domain. That's the corruption.
The shape of the medicine, in our style — one file, pure functions:
// src/shell/bigpay-acl.ts — the ONLY file that knows BigPay's shape
interface BigPayWebhook { // their model: snake_case, string cents
event: string; // "payment.succeeded"
amount: string; // "1250"
currency: string; // "usd"
reference: string; // our orderId
}
export function toPaymentCaptured(w: BigPayWebhook): Result<PaymentCaptured, AclError> {
if (w.event !== "payment.succeeded")
return { ok: false, error: "unknown payment event" };
const cents = Number(w.amount);
if (!Number.isInteger(cents) || cents < 0)
return { ok: false, error: "invalid amount from provider" };
return { ok: true, value: { type: "PaymentCaptured", orderId: w.reference,
amountCents: cents, currency: w.currency.toUpperCase() } };
}
Notice this is Lesson 1 all over again — parse, don't validate — applied at a
context boundary instead of a string boundary. The foreign payload is untrusted input; the output
is a proven value in your language. Everything downstream consumes
PaymentCaptured and cannot spell “BigPay”.
Contexts translate at their edges. One boundary remains unexamined: the database. Next lesson ties the whole course together with functional core, imperative shell — where I/O lives, and why your repository is just another parser.