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.

    No service degradation rules 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.

    Service degradation rule configured

Create a service degradation rule

  1. Log on to the EDAS console.
  2. In the left-side navigation pane, choose Traffic Management > Microservices Governance > Spring Cloud.
  3. In the navigation tree of the Spring Cloud page, click Service Degradation.
  4. In the top navigation bar, select a region. On the Service Degradation page, select a microservices namespace. Then, click Create Service Degradation Rule.
  5. In the Create Service Degradation Rule panel, set the parameters and click OK.
    Create a service degradation rule for a Spring Cloud application

    The following table describes the parameters.

    ParameterDescription
    Microservice SpaceSelect the region and microservices namespace to which the application belongs.
    Rule NameEnter 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 (-).
    DescriptionEnter a description for the service degradation rule.
    Service Provider ApplicationSelect the application that can be called by other applications.
    Degradation Consumer ApplicationSelect the application that you want to degrade.
    Service Degradation RulesClick Add Service Degradation Rule.
    Framework TypeSelect Spring Cloud.
    Service PathSelect the application that you selected for the Service Provider Application parameter and select the service path of the application.
    HTTP Request MethodSelect the request method for the application that you selected for the Service Path parameter.
    Effective PolicySelect the policy based on which the service degradation rule takes effect. Valid values: All Requests and Effective for Requests That Trigger Exceptions.
    Degradation PolicySelect 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 ValuesTurn 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.

Result

After you create and enable the service degradation rule, check whether the rule takes effect based on your business requirements.

What to do next

After you create the service degradation rule, you can edit the rule. You can also disable or enable the rule based on the status of the rule. If you no longer require the rule, you can delete the rule.