Models, language and why one model cannot serve everyone
A model is a simplification built for a purpose. See how a ubiquitous language ties conversations to code, why a growing business cannot keep one model for everyone, and how a bounded context gives each model its own boundary.
Contentsand lesson path
On this page
- Why it matters
- A model is a simplification with a purpose
- Ubiquitous language
- Why one model cannot serve everyone
- Bounded contexts: one model inside each boundary
- Check your understanding
- Apply it
- Review prompt
Lessons of Strategic Domain-Driven Design
- Models, language and why one model cannot serve everyone Concept · 15 min
- Big-picture EventStorming for a delivery business Worked example · 30 min
- Core, supporting and generic subdomains Concept · 20 min
- Finding bounded contexts and drawing the context map Lab · 30 min
- Context boundaries check Knowledge check · 6 questions
What you will learn
- Draw bounded contexts with their ubiquitous language and a context map naming each relationship pattern (for example customer-supplier, anti-corruption layer, open host service).
01. Why it matters
Hopwell Couriers is a fictional same-day courier that this skill follows from start to finish. Independent shops in one city book a delivery before 13:00, couriers collect the parcels in the afternoon, the hub sorts them, and each recipient gets their parcel inside a two-hour evening window that they picked. The software started as one web application with one database, written when Hopwell had three couriers. It now has forty, plus a hub team, two dispatchers and a finance clerk, and one word causes trouble in every meeting.
Ask four people what a delivery is and you get four answers. For the shop it is a request to take a parcel somewhere today. For a courier it is a doorstep where a parcel changes hands. For finance it is a line on a monthly invoice. For support it is the thing a customer is complaining about. None of these answers is wrong. The trouble starts when the software insists that there is only one.
This lesson explains why a growing business ends up with several models, each valid inside its own boundary. Strategic Domain-Driven Design (DDD), introduced by Eric Evans in 2003, calls that boundary a bounded context. The rest of the skill shows how to discover boundaries (lesson 2), where to spend effort (lesson 3) and how to map the relationships between contexts (lesson 4).
02. A model is a simplification with a purpose
A city has many maps. The bus map bends streets into straight lines and keeps only stops and connections. The street map keeps every road but ignores the bus lines. Each map leaves out most of the city on purpose, and each is useful for one job. Asking which map is correct misses the point; ask which map helps with the job in hand.
A software model works the same way. It is the set of concepts, rules and words that a team chooses in order to represent part of a business, expressed in classes, functions, tables and tests. The domain is the business area the software serves, here same-day delivery. Domain experts are the people who know it best: dispatchers, couriers, hub staff and finance. A model is good when it makes that team's rules easy to state and change, not when it records every fact about the domain.
A dispatcher planning tonight's routes needs each stop's address, its time window and how long a handover usually takes. A finance clerk needs the shop, the fee, any credit and the invoice month. A model that holds both views in one class serves neither group well: every field matters to someone and is noise to everyone else.
03. Ubiquitous language
Evans's answer to the gap between experts and developers is a ubiquitous language: one shared vocabulary, built from the model, that the team and its domain experts use everywhere, in conversation, documents, code and tests. If dispatchers say route and stop, the code has Route and Stop, not Job and JobItem that someone must translate in their head during every conversation. A test that reads like a dispatcher's own sentence is a test the dispatcher can check.
The DDD Reference, the free summary Evans published in 2015, states a rule that sounds small but matters: a change in the language is a change to the model. When experts start using a new word, or quietly stop using an old one, something in the business has usually changed. The team should find out what, and then rename classes, methods and modules to match.
A ubiquitous language has one more property. Inside its boundary every term has exactly one meaning. Suppose one Hopwell developer uses window for the slot a recipient picked, and another uses it for the hours a van may enter the pedestrian zone. The language is broken at that point, and the team repairs it by giving the second idea its own name, such as access hours. This is the key to the rest of the lesson: one language can stay that precise only for a limited group of people working on a limited part of the business.
04. Why one model cannot serve everyone
Early on, one model often works well enough: the same three people book, deliver and invoice, so every word means the same to all of them. As teams form around different jobs, the meanings drift apart, and each group's rules start to depend on fields that another group controls. Martin Fowler describes the same effect at an electricity company, where meter meant different things to different departments, and quotes Evans's conclusion that total unification of the model for a large system is neither feasible nor cost-effective.
The script below is the smallest version of Hopwell's problem. Booking, Last Mile (the couriers' side of the business) and Billing share one Delivery class. Last Mile writes status, and Billing's rule for what to charge reads it. The examples need no packages and were run with Python 3.12.
"""One Delivery class shared by Booking, Last Mile and Billing."""
from dataclasses import dataclass
@dataclass
class Delivery:
ref: str
window: str # Booking's word: the evening slot the recipient picked
status: str # Last Mile writes this field ...
fee_pence: int # ... and Billing reads both to decide what to charge
def billable(deliveries: list[Delivery]) -> list[str]:
"""Billing's rule, written in Last Mile's words."""
return [d.ref for d in deliveries if d.status == "delivered"]
evening = [
Delivery("HW-101", "18-20", "delivered", 650),
Delivery("HW-102", "19-21", "delivered", 650),
Delivery("HW-103", "20-22", "attempt_failed", 650),
]
print("billable before:", billable(evening))
# The courier app now records safe-place drops with a new word of its own.
evening[1].status = "left_in_safe_place"
print("billable after: ", billable(evening))python3 shared_model.pybillable before: ['HW-101', 'HW-102']
billable after: ['HW-101']Nothing crashed, and no test owned by the courier-app team would fail, yet Hopwell stopped charging for every safe-place drop. The courier-app team was right that a safe-place drop is a different kind of handover, proved by a photo instead of a signature. Billing was right that the shop should pay for it. The bug lives in the shared field, where one team's working vocabulary became another team's business rule without anyone deciding that it should.
05. Bounded contexts: one model inside each boundary
A bounded context is an explicit boundary inside which one model and its language apply consistently. Inside it, every term has one meaning and the team keeps the model sound. Outside it, other contexts may use the same words differently, and that is allowed. Where two contexts must work together, the boundary is crossed by an explicit translation that someone owns, not by a shared field that silently means two things.
Here is the same situation as two contexts. Last Mile publishes an event in documented words; Billing owns its own model of a charge and one function that decides what each Last Mile word means for money.
"""Two bounded contexts, two models and one explicit translation between them."""
from dataclasses import dataclass
# Last Mile context: the event it publishes, in its own published words.
@dataclass(frozen=True)
class ParcelDelivered:
ref: str
handover: str # "in_person" or "safe_place" in version 1 of the event
# Billing context: its own model of what a delivery means for money.
@dataclass(frozen=True)
class Charge:
ref: str
pence: int
reason: str
FEE_PENCE = 650
CHARGE_REASON = {"in_person": "delivered", "safe_place": "delivered"}
class UnknownHandover(Exception):
"""Last Mile used a word that Billing has not decided how to charge."""
def to_charge(event: ParcelDelivered) -> Charge:
"""The one place where Billing decides what a Last Mile word means."""
if event.handover not in CHARGE_REASON:
raise UnknownHandover(f"{event.ref}: no charging rule for {event.handover!r}")
return Charge(event.ref, FEE_PENCE, CHARGE_REASON[event.handover])
for event in [ParcelDelivered("HW-101", "in_person"),
ParcelDelivered("HW-102", "safe_place")]:
print(to_charge(event))
try:
to_charge(ParcelDelivered("HW-104", "with_neighbour"))
except UnknownHandover as problem:
print("stopped at the boundary:", problem)python3 two_contexts.pyCharge(ref='HW-101', pence=650, reason='delivered')
Charge(ref='HW-102', pence=650, reason='delivered')
stopped at the boundary: HW-104: no charging rule for 'with_neighbour'The same boundary in TypeScript; Node 22.18 and later run a .ts file directly by stripping its types:
// The same boundary in TypeScript. Node 22.18 or newer runs this file directly.
type ParcelDelivered = { ref: string; handover: string }; // Last Mile's published event
type Charge = { ref: string; pence: number; reason: string }; // Billing's own model
const FEE_PENCE = 650;
const CHARGE_REASON: Record<string, string> = {
in_person: 'delivered',
safe_place: 'delivered',
};
class UnknownHandover extends Error {}
function toCharge(event: ParcelDelivered): Charge {
const reason = CHARGE_REASON[event.handover];
if (reason === undefined) {
throw new UnknownHandover(`${event.ref}: no charging rule for '${event.handover}'`);
}
return { ref: event.ref, pence: FEE_PENCE, reason };
}
const events: ParcelDelivered[] = [
{ ref: 'HW-101', handover: 'in_person' },
{ ref: 'HW-102', handover: 'safe_place' },
];
for (const event of events) console.log(toCharge(event));
try {
toCharge({ ref: 'HW-104', handover: 'with_neighbour' });
} catch (problem) {
if (!(problem instanceof UnknownHandover)) throw problem;
console.log('stopped at the boundary:', problem.message);
}node two_contexts.ts{ ref: 'HW-101', pence: 650, reason: 'delivered' }
{ ref: 'HW-102', pence: 650, reason: 'delivered' }
stopped at the boundary: HW-104: no charging rule for 'with_neighbour'Two things changed. First, the rule that a safe-place drop is chargeable is now written in Billing's terms, where finance can read it. Second, when Last Mile introduced a new word, with_neighbour, the translation refused it instead of guessing. In production you would park such an event for review rather than crash; either way, an unknown word stops at the boundary. In the terms of lesson 4, Billing protects its model with an anticorruption layer. In a larger system the two jobs would sit apart: the translation maps Last Mile's words to Billing's terms, and Billing's own pricing rules set the amount.
A few points about bounded contexts often confuse people:
- A context is a boundary of a model, not of a deployment. It can be a package inside one application, a separate service or a bought product. Many teams start with modules and split them out later, when there is a reason to (see modular monoliths).
- A context is usually owned by one team. The DDD Reference describes the boundary in terms of team organisation, the parts of the application that use the model, and physical things such as code bases and database schemas. Two teams sharing one context must coordinate constantly to keep its language consistent.
- The same word in two contexts is expected. Hopwell will end up with delivery in three contexts, each defined in its own glossary.
- A context is not a subdomain. A subdomain is a part of the business problem; a context is a part of the solution. Lesson 3 explains the difference.
How do you notice that a boundary is needed? Listen for the same word carrying different rules, for experts who would never be asked about each other's decisions, for parts of the business that change for different reasons or at different speeds, and for meetings where someone says it depends who you ask. The next lesson shows a workshop that surfaces them quickly.
06. Check your understanding
07. Apply it
Take the skill's practice domain, a clinic appointment service. Write down three words that receptionists, doctors and the billing office use in different ways; appointment, patient and visit are good candidates. For each word, write one sentence per group that defines it in that group's terms, and one rule that only that group cares about. Then sketch, in Python or TypeScript, the one translation you would need if billing had to react to a receptionist's change. Keep your notes: lesson 4 turns glossaries like these into bounded contexts.
08. Review prompt
Without looking back:
- Why is it misleading to ask whether a model is correct, and what should you ask instead?
- What does a ubiquitous language require inside a bounded context, and what is allowed between two contexts?
- In
shared_model.py, which team made the mistake, and where did the bug really live? - Name three signals that one model should become two contexts.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.