Domain-driven design

Also known as: DDD

On this page 7

Domain-driven design (DDD) is an approach to software architecture and programming that places a model of the business domain at the center of the system, shaped jointly by developers and domain experts. Introduced by Eric Evans in his 2003 book of the same name, it targets software whose main difficulty lies in complex business rules rather than in technology.

DDD combines strategic design, which divides a large problem into coherent models with clear boundaries, and tactical design, which supplies building blocks such as entities, value objects and aggregates for expressing each model in code. Its aim is code that speaks the language of the business and changes as cleanly as the business itself changes.

Core ideas of domain-driven design

Domain-driven design rests on the idea that the domain model is the heart of the software, and that the model must be discovered through continuous collaboration rather than specified once. Developers and experts refine it together, and the code is treated as the most precise expression of that shared understanding.

The ubiquitous language is the practical tool for that collaboration. Every term used in conversations, documents, tests and class names means the same thing to everyone within one boundary. When an expert says that an order is confirmed rather than placed, the code uses that exact word, and a change in the language signals a change in the model.

A second central idea is that one universal model does not work for a large organization. The word customer means something different to billing, shipping and marketing, so DDD accepts several models and makes their boundaries explicit instead of forcing a single compromise.

Strategic design: bounded contexts and context maps

Strategic design in DDD organizes a system around bounded contexts, each of which is an explicit boundary inside which one model and one ubiquitous language apply consistently. A bounded context often aligns with a team and frequently with a deployable unit, although it is a linguistic and model boundary first, not a technical one.

The business is also divided into subdomains, which are classified by their strategic value. This classification guides where the organization invests its best modeling effort.

Subdomain typeBusiness roleTypical investment
Core domainSource of competitive advantageCustom code, best engineers, deep modeling
Supporting subdomainNeeded but specific to the businessSimpler custom code or outsourcing
Generic subdomainSolved the same way everywhereOff-the-shelf product or library
Subdomain types and how DDD treats them

A context map documents how bounded contexts relate to each other. Its patterns describe both technical integration and the power relationship between teams, which often explains why an integration is shaped the way it is.

PatternMeaningWhen it fits
Shared kernelTwo contexts share a small model subsetClosely cooperating teams
Customer-supplierUpstream team plans for downstream needsClear dependency with negotiation
ConformistDownstream adopts the upstream model as isNo influence over the upstream
Anticorruption layerTranslation layer protects the local modelIntegrating legacy or external systems
Open host serviceUpstream offers a published protocolMany consumers of one context
Separate waysNo integration at allIntegration costs exceed benefits
Common context map relationships

Tactical design: the building blocks

Tactical design provides patterns for expressing a model in object-oriented or functional code within a single bounded context. The building blocks separate things with identity from plain values and define where consistency rules are enforced.

Building blockDefining propertyExample
EntityIdentity persists through changesCustomer with a customer number
Value objectDefined only by its attributes, immutableMoney amount with currency
AggregateCluster with one root enforcing invariantsOrder with its order lines
Domain eventRecord of something that happenedOrder shipped
RepositoryCollection-like access to aggregatesOrder repository
Domain serviceOperation that belongs to no single objectCurrency conversion policy
FactoryEncapsulates complex creationBuilding a valid insurance policy
Tactical building blocks of DDD

The aggregate is the most consequential of these patterns. It defines a transactional consistency boundary: all invariants inside one aggregate hold after every transaction, while consistency between aggregates is usually eventual, propagated through domain events. Practitioners recommend small aggregates that reference others by identity, because large aggregates cause locking conflicts and slow loading.

Domain-driven design is a modeling discipline, not a layering scheme, so it complements rather than competes with most architectural styles. Hexagonal architecture and clean architecture are frequently used to keep a DDD model independent of databases and frameworks.

ConceptPrimary focusRelation to DDD
Hexagonal architectureIsolating the core through ports and adaptersCommon host structure for a domain model
Clean architectureDependency rule pointing inwardProtects the domain layer from frameworks
Repository patternAbstracting persistenceAdopted as a DDD building block
MVCSeparating presentation concernsOperates at the user interface edge
MicroservicesIndependent deployable servicesBounded contexts often guide service boundaries
How DDD relates to neighboring concepts

The link to microservices deserves care. A bounded context is a good candidate for a service boundary, yet one context may contain several services, and splitting along technical layers instead of contexts tends to produce a distributed monolith with chatty coupling.

When domain-driven design pays off and when it does not

DDD pays off when business complexity dominates technical complexity and the domain changes over the life of the system. Insurance, logistics, trading, healthcare administration and banking are classic examples, because their rules are numerous, interdependent and frequently revised.

It is poorly suited to simple CRUD applications, reporting tools or thin integration layers, where the full tactical toolkit adds ceremony without benefit. Strategic design, however, remains useful almost everywhere, because clarifying boundaries and vocabulary is cheap and prevents expensive misunderstandings.

  • Anemic domain model: entities hold data while all logic lives in services, which defeats the purpose of the model.
  • Tactical patterns without strategy: teams adopt aggregates and repositories but never define bounded contexts.
  • No access to domain experts: the ubiquitous language is invented by developers alone.
  • Oversized aggregates: one aggregate grows to cover a whole subdomain and becomes a bottleneck.

Collaborative techniques such as event storming and domain storytelling help teams discover events, commands and boundaries quickly, often in workshops of a few hours to a few days, before any code is written.

A plain-language summary

Domain-driven design means building software around the business, around how it actually works and talks. Programmers sit down with the people who know the work best, agree on the words they use, and make the program use exactly those words.

Large organizations are split into areas, much like departments in a company, and each area gets its own clear model with its own vocabulary. That way a change in shipping does not accidentally break billing, and everyone understands what the software is supposed to do.

An example from practice

A regional insurance company replaces a 20-year-old policy administration system. In a three-day event storming workshop, underwriters, claims handlers and developers map more than 150 domain events and identify four bounded contexts: underwriting, policy management, claims and billing. Underwriting is classified as the core domain, while billing is a generic subdomain served by a purchased product.

Inside policy management, a Policy aggregate enforces rules such as coverage limits, and changes are announced through events such as PolicyEndorsed. An anticorruption layer translates the old mainframe records into the new model during migration. The result is that rule changes requested by underwriters are implemented in days rather than months, because the code uses their terms and each change stays inside one context.