Course map

Topic 054 / Advanced

Domain-driven design

Chapter 4.5 · Domain-Driven Design

What and why

A modular monolith (→ 53) needs a principled way to decide where module boundaries go, and plain data modeling models tables, not the business rules that make those tables meaningful — leaving a gap between how the business talks about its domain and how the code represents it, a gap where misunderstandings and bugs both live. Domain-driven design (DDD) builds a ubiquitous language shared between domain experts and developers, used consistently in conversation, documentation, and code — the code's class and method names should be sentences a domain expert would recognize, not database-shaped abstractions. Builds on: → 53 (the module boundaries DDD informs).

Diagram

Without a ubiquitous language With a ubiquitous language
Expert: "when a task is marked done, archive its linked comments" Expert says the same sentence
Code: updateStatus(id, 3) — what is 3? Code: task.complete() → archives linked comments — same words, same operation, traceable both ways

How it works

  1. Hold structured conversations with whoever understands the business, and write down the exact terms they use for things and actions.
  2. Use those exact terms as class names, method names, and status values in code — complete(), not updateStatus(3).
  3. Notice where the same word means different things in different parts of the business (a "customer" in billing versus a "customer" in support) — that is a signal a boundary exists (→ 56).
  4. Model the tactical building blocks inside each boundary: entities, value objects, aggregates (→ 55).
  5. Keep the language current: when the business's vocabulary changes, the code's names change in the same change — a stale name is a stale model.

Practical example

(illustrative). In the task manager, domain experts say "assign," "complete," "reopen," "overdue" — the code uses exactly those method and state names (task.assign(user), task.complete()) instead of generic CRUD verbs, so a bug report phrased in business language ("reopening a completed task doesn't send a notification") maps directly to one method.

When to use it

  • Use when: the domain has real business rules worth protecting, and multiple people — developers and domain experts — need a shared vocabulary to avoid talking past each other.
  • Avoid when: the domain is simple CRUD with no disputed terminology and no domain expert to consult — the conversations and modeling effort cost more than the ambiguity they would prevent.
  • Failure scenarios: "DDD" applied as a checklist of entity/value-object/aggregate classes with no actual conversation behind the names — just another set of data classes with extra ceremony and none of the shared-understanding benefit.
  • Simpler alternative: a clear relational model and a plain service layer — for most CRUD applications, this is both simpler and sufficient.

Practice

(20–25 min; no lab services — any format). For the task manager, write a one-page glossary: term, one-line business definition, the code name it maps to (or the mismatch, if the code currently uses something else). Done when every term has exactly one code name, matching the word a domain expert would use.

Key takeaway

DDD is a discipline of shared, precise vocabulary that drives the code's names and, eventually, its boundaries. Done when you can: hand your glossary to someone who has never read the code and have them correctly guess what a method does from its name. Used next in → 55 (the tactical building blocks that implement the language), → 56 (the boundaries where the language stops being shared), → 144 (microservices decomposition later uses the same boundaries).

References

None — this topic makes no external claims.

Source directory

Search the guide