Article · DDD Strategic Design · Modular Monolith
DDD strategic design: subdomains, bounded contexts and context maps
The strategic part of Domain-Driven Design in practice: the ubiquitous language, core, supporting and generic subdomains, bounded contexts, context map patterns and the anticorruption layer. Examples in C#, TypeScript, Java, Go and Python.
At Halina's pierogi place, the word "order" means something different to everyone. For the dining room it's an agreement with a customer: lines, prices, a discount, a payment. For the kitchen it's a ticket: what to cook, at which station and how long it will take. For delivery it's a run: an address, a courier, a time. For accounting it's a document with VAT. For years everyone used a single Order class with eighty fields. Strategic Domain-Driven Design starts by admitting that this isn't one model but several – and each one needs its own boundaries.
- 2003
- "Domain-Driven Design" – Eric Evans; strategic design is part four of the book
- 3
- kinds of subdomain – core, supporting, generic
- 9
- classic context map patterns – from partnership to the "big ball of mud"
Context and forces
- One word, many meanings – the shared "order" model grows until nobody dares to change it.
- A limited budget – not every part of the system deserves a sophisticated model; payments and text messages are better bought.
- Teams and communication – model boundaries should let teams work without constant negotiation.
- Integrations with the outside world – courier platforms and payment gateways impose their own models, which shouldn't leak into ours.
In his 2003 book, Eric Evans devoted the "Strategic Design" part to these problems. They were later developed by, among others, Vaughn Vernon (Implementing Domain-Driven Design, 2013, and Domain-Driven Design Distilled, 2016) and Alberto Brandolini, the creator of Event Storming workshops.
Subdomains: where to invest
| Kind | Characteristics | In the pierogi place | Strategy |
|---|---|---|---|
| Core | Sets the company apart from competitors, complex, changes often | production planning and catering: how much of what to make, in what order, at what margin | the best people, a rich model, tactical DDD |
| Supporting | Needed and specific, but gives no advantage | the loyalty programme, shift rota | a simpler model, own code or a customised product |
| Generic | Everyone has the same problem | payments, SMS, invoicing, sign-in | buy it or use a ready-made service, integrate through an anticorruption layer |
The classification isn't permanent: if Halina starts competing on 20-minute delivery, logistics may be promoted from a supporting to a core subdomain.
Bounded contexts and the ubiquitous language
The ubiquitous language is the vocabulary shared by domain experts and developers, used in conversations, documentation and code. The key caveat: it is ubiquitous within a context. In the sales context an "order" has a price, in the kitchen context it doesn't – and that's fine. Trying to build one model for everyone ends with a model that fits nobody.
One word, two models in two contexts
namespace Pierogarnia.Sales
{
// SALES context: an order is a commercial agreement with a customer.
public sealed record Order(CustomerId Customer, IReadOnlyList<OrderLine> Lines, Money Total, PaymentStatus Payment);
}
namespace Pierogarnia.Kitchen
{
// KITCHEN context: the same real-world thing is a ticket to cook. No prices, no customer data.
public sealed record KitchenTicket(
int Number,
IReadOnlyList<ToCook> ToCook,
TimeSpan PrepTime, // what the kitchen actually cares about
Station Station); // boiling, frying, packing
public sealed record ToCook(Dumpling Dumpling, int Pieces);
}// SALES context: an order is a commercial agreement with a customer.
export namespace Sales {
export interface Order {
customerId: string;
lines: { sku: string; quantity: number; unitPrice: Money }[];
total: Money; // prices, discounts, loyalty points
payment: "pending" | "authorized" | "refunded";
}
}
// KITCHEN context: the same real-world thing is a ticket to cook. No prices, no customer data.
export namespace Kitchen {
export interface KitchenTicket {
number: number;
toCook: { dumpling: Dumpling; pieces: number }[];
prepMinutes: number; // what the kitchen actually cares about
station: "boiling" | "frying" | "packing";
}
}// SALES context (package pl.pierogarnia.sales): an order is a commercial agreement.
public record Order(CustomerId customer, List<OrderLine> lines, Money total, PaymentStatus payment) {}
// KITCHEN context (package pl.pierogarnia.kitchen): the same thing is a ticket to cook.
// No prices and no customer data - the kitchen doesn't need them, so the model doesn't have them.
public record KitchenTicket(int number, List<ToCook> toCook, Duration prepTime, Station station) {}
public record ToCook(Dumpling dumpling, int pieces) {}// package sales: an order is a commercial agreement with a customer.
type Order struct {
Customer CustomerID
Lines []OrderLine
Total Money // prices, discounts, loyalty points
Payment PaymentStatus
}
// package kitchen: the same real-world thing is a ticket to cook.
type KitchenTicket struct {
Number int
ToCook []ToCook
PrepTime time.Duration // what the kitchen actually cares about
Station Station // boiling, frying, packing
}# sales/model.py: an order is a commercial agreement with a customer.
@dataclass
class Order:
customer_id: str
lines: list[OrderLine]
total: Money # prices, discounts, loyalty points
payment: PaymentStatus
# kitchen/model.py: the same real-world thing is a ticket to cook. No prices, no customer data.
@dataclass
class KitchenTicket:
number: int
to_cook: list[tuple[Dumpling, int]]
prep_time: timedelta # what the kitchen actually cares about
station: Station # boiling, frying, packingThe rest of this article is for members
Create a free account or sign in to read it all. Still ahead:
- The context map
- The anticorruption layer in code
- How to find the boundaries
- Trade-offs
- In practice
- Anti-patterns
- Related topics
- Test yourself