BLUEPRINT · The Solution Architect's Codex
Ch 07 · Domain-Driven Design
Chapter 07 · Modelling the business, not the database

Domain-Driven Design — where software meets the language of the business

DDD is not a framework, library, or pattern catalog — it is a discipline for tackling complexity at the heart of the business. Strategic DDD aligns software boundaries with business meaning; tactical DDD provides the building blocks inside each boundary. When the domain is hard, no architecture style will save you without it.

7.1 · Why DDD

Published by Eric Evans in 2003 (Domain-Driven Design: Tackling Complexity in the Heart of Software), DDD answers a specific class of project failure: software that is technically excellent but does not capture how the business actually works. DDD pays off when business complexity dwarfs technical complexity. For a CRUD over a database it is overkill; for insurance underwriting, supply chains, healthcare claims, payments switching, telco mediation, or marketplace pricing it is often the only thing that works.

Vaughn Vernon's Implementing Domain-Driven Design (2013, the "red book") and Domain-Driven Design Distilled (2016) made the discipline practical; Vlad Khononov's Learning Domain-Driven Design (2021) refreshed it for modern microservice contexts.

7.2 · Strategic DDD

The strategic layer carves the problem domain into bounded contexts — explicit boundaries within which a single Ubiquitous Language is precise and unambiguous. The same word ("Customer", "Order", "Account") often means different things in different contexts; strategic DDD makes the differences visible instead of papering over them.

Context Maps — the nine relationship patterns

PatternMeaning
PartnershipTwo teams succeed or fail together; coordinated planning, mutual dependency.
Shared KernelTwo contexts share a small, agreed-upon subset of the model; changes need bilateral consent.
Customer / SupplierUpstream supplier accepts downstream customer's needs in its backlog.
ConformistDownstream accepts upstream's model as-is; no negotiation power.
Anti-Corruption Layer (ACL)Translation façade that keeps a foreign / legacy model from leaking inward.
Open Host Service (OHS)Published protocol any consumer may use; stable, generic interface.
Published LanguageShared, well-documented schema (e.g. industry standard) used between contexts.
Separate WaysIntegration cost is higher than value; the contexts simply don't talk.
Big Ball of MudThe honest label for legacy systems with no boundaries; isolate behind ACL.
Practice
Draw the context map as a diagram early. Annotate each edge with the relationship type. The map is more valuable than any internal diagram: it tells you where to invest in translation and where you can refactor freely.

7.3 · Tactical DDD — the building blocks

Inside a bounded context, DDD provides a small, opinionated set of building blocks. Used together they keep the domain model expressive and the infrastructure at arm's length.

BlockDefinition
EntityHas identity that persists through state changes (Customer #1234 is the same entity even if the name changes).
Value ObjectDefined entirely by its attributes; immutable; no identity (Money, Address, DateRange).
AggregateConsistency boundary: a cluster of entities + value objects treated as a single unit. The Aggregate Root is the only external entry point. All invariants inside hold at the end of every transaction.
Domain ServiceBusiness behaviour that doesn't naturally belong to a single entity (e.g. FundsTransfer across two accounts).
Application ServiceThin orchestration layer above the domain; coordinates use-cases, transactions, security; holds no business rules.
RepositoryCollection-like abstraction for retrieving and persisting aggregate roots. Hides the persistence mechanism.
FactoryEncapsulates complex aggregate construction so the rest of the model stays simple.
Domain EventAn immutable fact about something the domain has decided (OrderPlaced, PaymentCaptured). Past tense, named in the Ubiquitous Language.
// Aggregate boundary in Kotlin (tactical DDD)
class Order private constructor(
  val id: OrderId,
  private val lines: MutableList<OrderLine>,
  private var status: OrderStatus
) {
  fun addLine(sku: Sku, qty: Int): DomainEvent {
    require(status == OrderStatus.DRAFT) { "only DRAFT orders may change" }
    lines += OrderLine(sku, qty)
    return OrderLineAdded(id, sku, qty)
  }
}

7.4 · EventStorming — Alberto Brandolini

EventStorming (2013) is a fast, low-tech workshop format using coloured sticky notes on a wall (or virtual whiteboard) to map a business process. There are three levels of fidelity:

  1. Big Picture — explore the whole business, surface chaos, find hot spots.
  2. Process Modelling — for a chosen slice, add commands, actors, policies, read models.
  3. Software Design — refine until aggregates and bounded contexts emerge.
ColourSticky meaning
OrangeDomain Event (past tense — "OrderPlaced")
BlueCommand (imperative — "PlaceOrder") triggered by an actor
YellowAggregate (state on which a command acts)
PinkExternal system
PurplePolicy (whenever X happens, do Y)
GreenRead model / view used to make a decision
RedHot spot — a question, conflict, or known unknown

7.5 · Event Modeling — Adam Dymitruk

Event Modeling (2018) is a more rigorous, swimlane-based descendant of EventStorming. The board is divided into vertical slices — each a single user-visible workflow — and horizontal swimlanes (UI, command, event, read model). It is particularly well-suited to systems that will use Event Sourcing + CQRS because the model maps almost 1-to-1 to implementation. Where EventStorming explores, Event Modeling specifies.

7.6 · Subdomain types — Core, Supporting, Generic

TypeDefinitionInvestment strategy
CoreCompetitive differentiator; the reason customers pay youBuild in-house, best engineers, deepest DDD modelling
SupportingNecessary but not differentiatingBuild pragmatically, or buy if a good fit exists
GenericSolved problem available off-the-shelf (auth, billing, search)Buy / SaaS; never build
Architect's bias
Teams routinely misclassify the auth/billing/CMS as "core" because they want to build it. Tag a subdomain as core only if losing it would lose customers.

7.7 · Sizing bounded contexts

"One bounded context per microservice" is a heuristic, not a rule. The right size is determined by: (a) consistency requirements — what must change atomically lives together; (b) team topology — Conway's Law; (c) rate of change — features that ship together belong together; (d) data volume and access patterns. A context can legitimately be a modular monolith, a single service, or a small constellation of services. The boundary is the language boundary, not the deployment boundary.

Context Map — three bounded contexts

Sales (core) Aggregates: Quote · Order Events: OrderPlaced Billing (supporting) Aggregates: Invoice · Payment Events: InvoiceIssued CRM (generic, SaaS) External system Wrapped by ACL U/S ACL

7.8 · DDD & microservices

Microservices and DDD reinforce each other when used together correctly: each service owns one bounded context (or part of one) and exposes its Ubiquitous Language through an Open Host Service or Published Language. The classic mistake is technical decomposition — splitting by layer (auth-service, db-service, ui-service) or by entity (user-service, order-service, product-service) instead of by business capability. The result: every business operation requires a chatty orchestration across many services, and a single domain change ripples through all of them.

Failure mode
Entity-per-service is a distributed monolith in disguise. Decompose by behaviour and consistency boundary, not by noun.

7.9 · Common DDD anti-patterns

  • Anemic Domain Model (Fowler 2003) — entities are bags of getters/setters; all behaviour lives in services. The "domain" model is a data structure pretending to be a model.
  • God Aggregate — one aggregate root tries to enforce every invariant in the system; performance and merge-conflict nightmares follow.
  • Infrastructure leaking into the domain — domain classes import JPA annotations, HTTP frameworks, or message-broker clients. Use Hexagonal (Ch 06) to keep the centre clean.
  • Ignoring the Ubiquitous Language — code uses different words from the business ("User" in code, "Member" in conversation); knowledge bleeds out at every handoff.
  • Premature tactical DDD — adopting aggregates and value objects without first establishing bounded contexts. The patterns are local; the strategy is global.
  • One context = one service, always — converts a useful heuristic into a religion; produces over-decomposed systems.

7.10 · Self-check

Q1 · The Ubiquitous Language must be precise within which scope?
The whole company
A single bounded context
A single microservice
A single team
Q2 · An Anti-Corruption Layer is most useful when…
two greenfield teams co-design a shared kernel
a foreign / legacy model would otherwise pollute your domain
you want to publish events to many consumers
you want to avoid versioning APIs
Q3 · In EventStorming, an orange sticky note represents…
A command issued by an actor
A Domain Event, past tense
A policy
An external system
Q4 · For a "Generic" subdomain (e.g. authentication), the recommended investment strategy is…
Build it in-house with your best engineers
Model it with the deepest tactical DDD
Buy or use SaaS; do not build
Outsource and rewrite later