# Managing Domain Complexity
> **In one sentence:** when different parts of the business mean different things by the same
> word, don't force one model. Give each meaning its own explicit boundary.

## When models disagree

Picture a company where **marketing** and **sales** both talk about "leads".

- To marketing, a lead is a *moment*: someone filled in a form and showed interest.
- To sales, a lead is a *journey*: a long process with stages, calls, follow-ups and an outcome.

People cope with this easily because context tells them which meaning is intended. Code doesn't.
The usual fixes fail:

- **One giant shared model** (the wall-sized ER diagram) tries to serve everyone and serves no one
  well. It is too heavy for marketing and too thin for sales.
- **Prefixing names** ("marketing lead" and "sales lead") adds mental load, invites mistakes and
  doesn't match how anyone actually talks.

## Bounded contexts

DDD's move: **split the language.** Each smaller language applies inside an explicit boundary,
its **bounded context**. "Lead" can exist in both the Marketing context and the Sales context, as
long as it has exactly one meaning inside each.

- A model needs a boundary. Without one, it keeps growing until it tries to copy reality.
- A ubiquitous language is only "ubiquitous" **inside its bounded context**. It is not company-wide.
- Conflicting terms are normal in any business of real size. Bounded contexts make those contexts
  explicit instead of hidden.

## Choosing the size

- Language conflicts set the **maximum** size of a context. You can always make it smaller.
- Small isn't automatically good. Large contexts are hard to keep consistent, and many small
  contexts cost more to integrate. Aim for *useful*.
- Reasons to split further include new teams, parts that need different release cycles, and parts
  that must scale on their own.
- **Don't cut through a cohesive group of use cases** that work on the same data. Every change
  would then hit both sides and force them to deploy together.

## Subdomains versus bounded contexts

| | Subdomains | Bounded contexts |
|---|---|---|
| Where they come from | **Discovered**, because the business strategy defines them | **Designed**, because you choose them |
| Question answered | What does the business do? | How do we divide the models and the software? |

Possible arrangements include one context for a whole small system, contexts split along language
conflicts, or one context per subdomain. A one-to-one match is fine, but it isn't required, and
sometimes two different models of the same subdomain are useful at once, the same way you'd carry
two kinds of map.

## Physical and ownership boundaries

- **Physical:** each bounded context is its own service or project. It is built, versioned and
  deployed independently and can use a different tech stack. If a context holds several
  subdomains, those are *logical* boundaries inside it, such as modules, packages or namespaces.
- **Ownership:** a bounded context belongs to **exactly one team**. One team can own several
  contexts, but two teams never share one. That stops teams making silent assumptions about each
  other's models and pushes them to agree explicit contracts.

## Everyday examples

- **Words in different fields.** "Port", "monitor" and "driver" mean different things to a network
  engineer, a hardware engineer and a race fan. Each field is its own semantic area.
- **Is a tomato a fruit?** A botanist says yes (it carries seeds). A cook says it's a vegetable
  (savory, cooked). Tax law in one country once officially called it a vegetable too. Each answer
  is right *in its own context*.
- **Competing theories.** Classical and relativistic physics contradict each other, yet each is
  the right tool in its own range.
- **Will the fridge fit?** A sheet of cardboard cut to the fridge's footprint checks the doorway
  width, and a tape measure checks the height. Two crude, single-purpose models beat one detailed
  replica, which would be over-engineering. (A phone AR scanning app would be the "buy a generic
  solution" option.)

## Check yourself

1. Which are discovered and which are designed: subdomains or bounded contexts?
2. A bounded context is a boundary of what?
3. Is a smaller bounded context always better?
4. Can two teams share a bounded context? Can one team own two?

<details><summary>Answers</summary>

1. Subdomains are discovered; bounded contexts are designed.
2. A model, a lifecycle and ownership.
3. No. It depends on the project and its constraints.
4. No, and yes.

</details>
