Strategic Design: Bounded Contexts & Context Mapping

Strategic Design is a crucial part of Domain-Driven Design that focuses on the "big picture" of your system. It helps in understanding and organizing complex domains by breaking them down into manageable, independent parts. The two primary tools of Strategic Design are Bounded Contexts and Context Mapping.

High-level architectural diagram representing interconnected bounded contexts.

Bounded Contexts

A Bounded Context defines the explicit boundary within which a particular domain model is consistent and has a specific meaning. Inside a Bounded Context, terms and concepts from the Ubiquitous Language have a precise, unambiguous definition. However, the same term might have a different meaning in another Bounded Context.

For example, the term "Customer" might mean one thing in a "Sales" context (e.g., focusing on purchase history and contact details) and something different in a "Support" context (e.g., focusing on support tickets and issue resolution). Each context has its own model tailored to its specific needs.

Why are Bounded Contexts important?

  • Clarity and Precision: They ensure that the language and model within a specific part of the system are clear and unambiguous.
  • Autonomy: Teams can develop and evolve their Bounded Contexts independently, reducing dependencies and potential conflicts. This is particularly relevant in microservice architectures, as discussed in DDD & Microservices.
  • Model Integrity: They protect the integrity of a domain model by clearly defining its scope of applicability.

Defining clear boundaries is essential, just like in financial planning where understanding different asset classes and their risk profiles helps in building a robust portfolio. For instance, Pomegra's AI Portfolio Builder helps users manage custom portfolios by considering risk profiles and financial objectives, reflecting a form of contextual clarity in finance.

[Diagram: Illustration of two Bounded Contexts, e.g., "Sales Context" and "Support Context", showing different aspects of a "Customer" model within each. Icons like building blocks could be used.]

Context Mapping

Once you have identified various Bounded Contexts, you need to understand how they relate to each other. This is where Context Mapping comes in. A Context Map is a diagram or document that illustrates the relationships and integrations between different Bounded Contexts.

There are several patterns for Context Mapping, each describing a different type of relationship:

  1. Shared Kernel: Two or more Bounded Contexts share a common subset of the domain model. This requires close collaboration.
  2. Customer-Supplier: One Bounded Context (the customer) depends on another (the supplier). The supplier dictates the terms of the relationship.
  3. Conformist: A Bounded Context conforms to the model of another, typically when integrating with a legacy system or an external service whose model cannot be easily changed.
  4. Anticorruption Layer (ACL): A Bounded Context creates a translation layer to protect its model from the influence of another system's model. This is crucial for maintaining model integrity when integrating with external or legacy systems.
  5. Open Host Service (OHS): A Bounded Context defines a well-documented protocol or API that other contexts can use to integrate with it.
  6. Separate Ways: The Bounded Contexts have no direct integration or relationship. This is chosen when integration provides little value or is too costly.
  7. Partnership: Two Bounded Contexts are mutually dependent and must evolve together. This requires close coordination between the teams.
Abstract representation of different context mapping patterns like shared kernel or anticorruption layer.

Understanding these patterns helps teams make conscious decisions about how to integrate different parts of a large system, ensuring that these integrations are managed effectively. This macroscopic view is vital, much like how understanding Edge Computing helps in designing distributed systems.

Strategic Design provides the blueprint for structuring your application around the business domain. By clearly defining Bounded Contexts and their relationships through Context Mapping, you lay a solid foundation for building complex, maintainable, and scalable software. The next step is to look at Tactical Design, which deals with the building blocks within a Bounded Context.