Coupling
Coupling in distributed systems refers to the degree of interdependence between different components or services within the system. It measures how closely connected and reliant the components are on each other.
In a tightly coupled system, components are highly dependent on each other. Changes in one component often require changes in others.
In a loosely coupled system, components operate independently and interact through well-defined interfaces or protocols. Changes in one component have minimal impact on others.
Tight Coupling | Loose Coupling | |
---|---|---|
Dependency | High Dependency | Low Dependency |
Scalability | Difficulty in Scalability | Ease of Scalability |
Maintenance | Maintenance Complexity | Simpler Maintenance |
Types of Coupling
In a distributed system, there are mainly 5 types of coupling.
it is always desirable to keep the coupling as low as possible. Keeping that in mind, the below image represents the different types of coupling and their strength in terms of how tightly they couple the systems.
Domain Coupling
Domain coupling refers to the dependencies between different parts of a system based on their functional or business logic. It occurs when services are linked by their shared domain or business context.
Example
In an order management system, Order service and inventory service are domain coupled since they share the same domain (i.e., order management). Changes in business rules for inventory (e.g., how stock levels are checked or updated) might affect how the Order Service operates.
Temporal Coupling
Temporal coupling refers to the dependencies between different parts of a system based on the timing or sequence of operations. It occurs when services interacts synchronously in a fixed execution order or timing constraints.
Example
In an order management system, Order service is temporally coupled to inventory service because there are sequential steps which need to be performed with in a fixed time to place an order.
Step 1: Order Service must first check the Inventory Service to confirm that the items are available.
Step 2: Order Service update the Inventory Service to decrease the stock levels accordingly.
Step 3: Order Service creates an order.
Pass-through Coupling
Pass-through coupling refers to a situation where one service acts as an intermediary between two services. It accepts data from one service and passes it to another without adding significant processing or logic of its own. This type of coupling can create unnecessary dependencies and complexity in the system, as it introduces additional layers that do not contribute to meaningful functionality.
Example
Suppose in an order management system,
- Order Service sends shipment details along with order items to the Inventory Service.
- Inventory Service reduces the inventory stock based on the order items.
- Inventory Service then passes the shipment details to the Delivery Service.
Common Coupling
Common coupling refers to a situation where more than one service (or component) are responsible for managing a data. Common coupling can be seen in the services which share the common database or file store.
Example
Suppose in an order management system, Order service can set the order state to either CREATED or CONFIRMED and delivery service can set it to DELIVERED.
Content Coupling
Content Coupling refers to a situation where one service directly changes the data which is managed by some other service.
Example
Suppose in an order management system, Order service manages all the state of an order which is CREATED, CONFIRMED and DELIVERED but instead of asking order service to update the order state, delivery service directly update the status by accessing the database.