DDD: Bounded Contexts — Where Models Apply
A bounded context is the explicit boundary within which a domain model is consistent — the same word means different things across boundaries.
When to use
- Large domain with multiple teams or subdomains
- Preventing model pollution across services
- Defining microservice or module boundaries
Tradeoffs
- Context mapping adds coordination overhead at boundaries
- Misaligned context and team boundaries cause friction
- Go
- Python
// package sales
type Customer struct {
ID string
Name string
CreditLimit float64
SalesRepID string
}
// package shipping
type Customer struct {
ID string
Name string
ShippingAddress Address
DeliveryPrefs string
}
# module: sales/models.py
from dataclasses import dataclass
@dataclass
class Customer:
id: str
name: str
credit_limit: float
sales_rep_id: str
# module: shipping/models.py
@dataclass
class Customer:
id: str
name: str
shipping_address: str
delivery_prefs: str
Gotcha: A microservice boundary should align with a bounded context boundary — not the other way around.