The customer-supplier relationship is a bounded context relationship in which one bounded context is dependent on another for its functionality or data. The dependent bounded context is called the customer, while the independent context is called the supplier. The customer makes requests to the supplier, and the supplier provides responses to fulfill those requests.
The customer-supplier relationship is often used when one bounded context requires information or functionality from another bounded context. By establishing a clear dependency between the two contexts, changes can be made to one context without affecting the other, as long as the interface between them remains stable. This allows for greater modularity and flexibility in the overall system architecture.
Implications
The customer-supplier relationship between bounded contexts has the following pros and cons:
Pros
- Clear separation of concerns between the two bounded contexts
- Can facilitate modularization and encapsulation of functionality
- The supplier context can focus on providing a specific service or functionality to the customer context
- The customer context can rely on the supplier context for specific functionality without needing to understand the implementation details
Cons
- Tight coupling between the two contexts, which can make it difficult to change one context without affecting the other
- Can lead to the proliferation of APIs and dependencies between the two contexts
- Requires careful management of the interface and contract between the two contexts to ensure that they remain compatible
- Can lead to a lack of collaboration and communication between the teams responsible for the two contexts, which can hinder overall progress and understanding
Overall, the customer-supplier relationship can be useful in certain situations, but it requires careful management and communication to ensure that the two contexts remain compatible and that changes to one context do not have unintended consequences for the other.
Example
Let’s consider an e-commerce application where customers can place orders and the system needs to manage the inventory of products. In this case, we can have two bounded contexts:
- Order Management Bounded Context: This context manages all the activities related to orders such as placing orders, managing order history, managing shipping and delivery status, etc. This context has a customer role as it interacts with the customer directly.
- Inventory Management Bounded Context: This context manages the inventory of products such as adding and removing products, tracking product stock levels, and notifying when stock levels are low. This context has a supplier role as it provides the necessary inventory data to the Order Management Bounded Context.
In this example, we can see that the Inventory Management Bounded Context is acting as a supplier to the Order Management Bounded Context which is acting as a customer. The Inventory Management Bounded Context provides the necessary information to the Order Management Bounded Context to ensure that the inventory levels are updated correctly and orders can be fulfilled.
The key point to note here is that the two bounded contexts have clearly defined roles and responsibilities. The Order Management Bounded Context relies on the Inventory Management Bounded Context for inventory-related data and the Inventory Management Bounded Context is responsible for maintaining and updating the inventory data.
When does it work?
The customer-supplier relationship can work effectively in the following situations:
- Well-defined interface: When the interface between the bounded contexts is well-defined, it makes it easier to establish a clear customer-supplier relationship.
- Clear responsibilities: When the customer and supplier have clear responsibilities, it makes it easier to ensure that each context is focused on its own domain and can be developed independently.
- Limited dependencies: When the customer-supplier relationship involves limited dependencies, it reduces the risk of coupling between the contexts.
- Strong communication: When the customer and supplier communicate effectively and frequently, it helps to establish a collaborative and productive relationship.
- Shared vision: When the customer and supplier share a common vision and goals, it facilitates cooperation and enables the partnership to be more effective.
When does it not work?
The customer-supplier relationship in DDD may not work in certain scenarios such as:
- Tight coupling: If the customer and supplier contexts become tightly coupled, any change in one context may require changes in the other, which defeats the purpose of defining independent bounded contexts.
- Misalignment of business goals: If the business goals of the customer and supplier contexts are not aligned, it may lead to conflicts and difficulties in defining interfaces and contracts.
- Inadequate communication: Effective communication is critical to ensure that the customer and supplier contexts understand each other’s needs and requirements. Inadequate communication can lead to misunderstandings and result in poorly defined interfaces and contracts.
- Overreliance on a supplier context: If a customer context becomes too dependent on a supplier context, it may cause problems if the supplier context fails or changes in ways that do not meet the customer’s needs.
- Lack of domain expertise: If the customer context lacks domain expertise and relies heavily on the supplier context for guidance, it may lead to poorly defined interfaces and contracts.