Domain Coupling

Definition

Domain coupling refers to the dependencies between services because they contain the functionals or business logics which are required to solve the problems related to a specific domain.

Example

In an order management system, Order, inventory, delivery, and billing services are domain-coupled because they belong to the same domain, i.e., order management. These services collaborate to provide solutions related to order management, such as creating orders, managing orders, and displaying order or payment history to users.

In this context, changes in one service require changes in other services. For example, if the order service calls the delivery service to initiate a delivery after an order is created, and the delivery service now requires a new field (such as a landmark) to improve delivery accuracy, the order service must be updated to handle this new field. This ensures that information from upstream services can be appropriately passed to the delivery service.

Handle Domain Coupling

Domain coupling cannot be entirely avoided in a distributed system, as different services must work together to address domain-specific problems.

However, excessive dependency between services or a single service communicating with multiple services can be problematic. In such cases, it is advisable to redistribute some responsibilities. For example, if the order service manages orders and also communicates with inventory and delivery services, we can offload this communication responsibility. This can be achieved by either moving the communication to an upstream service, such as the API layer, or by introducing a dedicated service, such as an order processing service, to handle these interactions.