Course map

Topic 056 / Advanced

Bounded contexts and domain boundaries

Chapter 4.5 · Domain-Driven Design

What and why

Aggregates (→ 55) draw a consistency boundary around a handful of objects, but a large system has many aggregates and many teams, and the same word ("Product," "Customer") legitimately means different things in different parts of the business — forcing one shared model across all of it produces a model that is subtly wrong everywhere. A bounded context is an explicit boundary — a module, a modular-monolith module (→ 53), or eventually a service — inside which a model and its ubiquitous language (→ 54) are internally consistent; the same term can mean something different in a different bounded context, and that is not a bug. A context map records how bounded contexts relate — which one is upstream, which translates terms at the boundary. Builds on: → 55.

Diagram

┌── Catalog context ──┐    ┌── Ordering context ──┐    ┌── Shipping context ──┐
│ "Product": full      │───►│ "Product": just an    │───►│ "Product": a weight   │
│  description, price,  │    │  id + price snapshot   │    │  and a destination    │
│  images, categories   │    │  at order time          │    │  — nothing else       │
└───────────────────────┘    └────────────────────────┘    └───────────────────────┘
Same word, three deliberately different models — each adequate for its own context.

How it works

  1. List the distinct areas of the business (catalog, ordering, payment, shipping) and, for each, the terms that area uses.
  2. Where the same term carries a different meaning or different required fields across two areas, that is a context boundary — do not force one shared class to serve both.
  3. Draw the context map: which context is the source of truth for a concept, and which contexts merely consume a translated, smaller copy of it (ordering does not need the catalog's full product record, only an id and a price snapshot).
  4. Decide, per boundary, whether it stays a module inside one modular monolith (→ 53) or becomes a separately deployed service (→ 143–145) — that decision is about team and scaling independence, not about DDD itself.
  5. At every boundary crossing, translate explicitly rather than letting one context's internal model leak into another's code.

Practical example

(illustrative). For an e-commerce domain: four bounded contexts — Catalog, Ordering, Payment, Shipping — each with its own meaning for "Product" or "Order"; the Order aggregate (→ 55) lives inside the Ordering context and references a product only by id and price snapshot, never by importing Catalog's full Product class.

When to use it

  • Use when: a system has grown multiple areas with genuinely diverging vocabulary and rules, especially before deciding on service boundaries (→ 145) — getting this wrong here propagates directly into a wrong service split.
  • Avoid when: a small system has one shared, uncontested vocabulary — the boundaries and translation layers are pure overhead there.
  • Failure scenarios: no explicit boundaries, so "Product" ends up as one bloated class with fields for catalog, pricing, shipping, and tax all mixed together, changed by every team, broken by all of them.
  • Simpler alternative: one shared domain model for a small, single-team system; introduce bounded contexts only once a second team or a second genuinely divergent meaning of the same term appears.

Practice

(20–25 min; no lab services — any format; this chapter's bounded-context exercise). For an e-commerce domain, identify four bounded contexts (catalog, ordering, payment, shipping); write one sentence per context stating what "Product" or "Order" means there; draw the context map showing which context is upstream of which. Done when you can name one term that means something different in two contexts and explain why that is correct, not a bug.

Key takeaway

Bounded contexts let the same word mean different, locally correct things; errors in service boundaries almost always trace back to a bounded context drawn wrong here. Done when you can: name a term that should not be shared across two parts of your system, and say why. Used next in → 143 (deciding whether a context becomes a separate service), → 144 (microservices decomposition), → 145 (bounded contexts are the primary input to service boundaries).

References

None — this topic makes no external claims.

Source directory

Search the guide