Temporal Coupling

Definition

Temporal Coupling describes the situation where two or more than two services communicate synchronously so that they can perform a task (such as order creation) in a specific sequence and within the fixed time boundary.

Example

In an order management system, the process of creating an order involves the following steps:

Step 1: The Order Service first checks the availability of items by making a synchronous API call to the Inventory Service.

Step 2: If the items are available, the Order Service makes another API call to the Inventory Service to update the stock levels.

Step 3: If the above steps complete successfully, the Order Service proceeds to create the order.

Step 4: After the order is created, the Order Service makes an API call to the Delivery Service to initiate the delivery process.

Only after the successful completion of all four steps can the system confirm the order placement to the user.

This process reveals the following constraints:

  • The steps must be completed in the specified order.
  • The steps must be completed within a reasonable time frame since the user is waiting for confirmation.

Because of these constraints, we can say that the Order Service is temporally dependent on the Inventory and Delivery Services and the system has the temporal dependency.

Handle Temporal Coupling

Although, we can reduce the number of synchronous interactions between services which are required for successful response. Eliminating it completely might not be possible in all the cases and would be unnecessary. There is nothing wrong with performing business transactions in this way, but excessive use of these types of synchronous interactions can make the services highly dependent on each other.

In order to reduce the synchronous calls, we can use the asynchronous communication methods like messaging. In our example, we can use the messaging to remove the synchronous interaction between order and delivery services. Below are the steps:

Step 1: Order Service checks the items’ availability by making a synchronous API call to the Inventory Service.

Step 2: If the items are available, Order Service makes another API call to the Inventory Service to update the stock levels.

Step 3: If the above steps complete successfully, Order Service creates the order.

Step 4: After order creation, Order Service sends a command to a message queue to notify the Delivery Service to initiate the delivery process.

Step 5: Delivery Service listens to the message queue and processes the delivery initiation asynchronously.

By using asynchronous communication for the interaction between the Order Service and the Delivery Service, we decouple their temporal dependency, reducing the risk of blocking operations and improving overall system resilience and scalability.