The Complete Guide to Domain-Driven Design
Bounded Contexts in Practice
Bounded Contexts are perhaps the most important concept in DDD. Getting context boundaries right determines whether your system scales gracefully or becomes a tangled mess.
Identifying Bounded Contexts
Context boundaries often align with organizational boundaries (Conway's Law), but not always. Look for:
- Language differences—same terms meaning different things
- Independent change rates—parts that evolve at different speeds
- Team boundaries—natural ownership divisions
- Data ownership—where does authoritative data live?
- Consistency requirements—what must be transactionally consistent?
Context Communication Patterns
Contexts need to communicate. The patterns used depend on coupling requirements:
Synchronous (APIs): Direct calls between contexts. Simple but creates runtime coupling. Use when immediate consistency is required.
Asynchronous (Events): Contexts publish events; others subscribe. Looser coupling, eventual consistency. Better for scale and resilience.
Anti-Corruption Layer: Translation layer that protects your domain model from external systems. Essential when integrating with legacy systems or third-party APIs.
Bounded Contexts and Microservices
Bounded contexts often map to microservices, but the relationship isn't one-to-one. A bounded context might be implemented as multiple services, or multiple small contexts might share a service. The key is that service boundaries respect context boundaries—a service shouldn't span multiple contexts.