In a distributed microservices system, services may experience delays or failures due to various reasons. Such delays can propagate throughout the network, causing a chain reaction that impacts user experience. Timeouts prevent a single slow service from adversely affecting the overall system. When a dependent service exceeds a configured waiting period, it automatically fails and returns an error, keeping the rest of the network responsive. For example, if the rating service slows down, requests may get queued at the review service and the product page service. Similarly, if the details service becomes unresponsive, the product page service experiences delays, ultimately affecting all users. Implementing timeouts ensures that a service will not wait indefinitely for a slow response, thereby isolating faults and preserving system resilience.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Configuring Timeouts on the Product Page Service
Consider a scenario with a details service and a booking service that routes traffic to the product page. To prevent the system from waiting indefinitely for a response from the product page service, you can configure a timeout such that if the service takes longer than three seconds to respond, the request is automatically rejected. This is accomplished by adding a timeout option in the service configuration. Below is the VirtualService configuration that applies a three-second timeout to the product page:Configuring the Details Service
The details service configuration does not include a timeout. Instead, it is set up to route traffic normally. Here is the configuration for the details service:Simulating Service Failures with Fault Injection
To test how the system handles delayed responses, you can simulate a fault. For instance, introduce a fixed delay of five seconds for 50% of the traffic directed to the details service. This fault injection approach helps in validating the resilience of the system by forcing the product page service’s three-second timeout to trigger.Fault injection is a valuable technique for examining the robustness of microservices architectures. It enables you to proactively identify weak points in your system’s failure handling mechanisms.