During peak hours, a downstream service provider may experience a performance bottleneck that even affects your business. In this case, you can use the service degradation feature to degrade some service consumers. Unimportant service consumers do not call the services provided by the provider. Instead, degraded responses are directly returned. Valuable resources of the downstream service provider are reserved for key service consumers. This way, the overall service stability is improved.
Background information
Existing open source circuit breakers, such as Sentinel and Hystrix, break the circuits for unstable calls to services with weak dependencies. This implementation protects against overall system failures that are caused by unstable calls. Circuit breaking is a self-protective feature that is configured on service consumers in most cases.
The service degradation feature can be enabled regardless of whether a service call is normal. This feature protects service providers and ensures that resources are preferentially allocated to key service consumers.
The following example shows how to use service degradation in Spring Cloud applications.
- Service degradation rules are not configured.
By default, Consumers 1, 2, and 3 call all the paths of productservice in ProductService. The paths are /getIp, /product/{id}, and /products.
The following figure shows the call relationship when service degradation rules are not configured.
- A service degradation rule is configured.
You can configure a degradation rule to use when Consumer 1 calls the /getIp path of productservice in ProductService.
When you configure the service degradation rule, select Return Custom Json Data from the Degradation Policy drop-down list and select All Requests for Effective Policy. After this rule is configured, if Consumer 1 wants to call the /getIp path of productservice, Consumer 1 triggers local service degradation based on the configured rule without calling ProductService.
The following figure shows the call relationship after the service degradation rule is configured.
Create a service degradation rule
- Log on to the EDAS console.
- In the left-side navigation pane, choose .
- In the navigation tree of the Spring Cloud page, click Service Degradation.
- In the top navigation bar, select a region. On the Service Degradation page, select a microservices namespace. Then, click Create Service Degradation Rule.
- In the Create Service Degradation Rule panel, set the parameters and click OK.
The following table describes the parameters.
Parameter Description Microservice Space Select the region and microservices namespace to which the application belongs. Rule Name Enter a name for the service degradation rule. The name must be 1 to 64 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). Description Enter a description for the service degradation rule. Service Provider Application Select the application that can be called by other applications. Degradation Consumer Application Select the application that you want to degrade. Service Degradation Rules Click Add Service Degradation Rule. Framework Type Select Spring Cloud. Service Path Select the application that you selected for the Service Provider Application parameter and select the service path of the application. HTTP Request Method Select the request method for the application that you selected for the Service Path parameter. Effective Policy Select the policy based on which the service degradation rule takes effect. Valid values: All Requests and Effective for Requests That Trigger Exceptions. Degradation Policy Select a policy for service degradation from the drop-down list based on your business requirements. Valid values: Return Null Value, An exception returned, Return Custom Json Data, and Customize Callback. Use Default Values Turn on or off the switch to enable or disable the rule. - On: enables the rule after it is created. This is the default value.
- Off: disables the rule after it is created. To enable the rule, find the rule on the Service Degradation page, and then click Enable in the Operation column.