All Products
Search
Document Center

API Gateway:Configure a retry policy

Last Updated:Jan 07, 2025

Cloud-native API Gateway allows you to configure route-level retry policies. This allows you to configure automatic retries for failed requests. In a retry policy, you can specify retry conditions, such as failed connections, unavailable backend services, or a response with a specified HTTP status code.

Retry conditions

If the backend service returns a 5xx status code, your cloud-native gateway automatically retries the failed request for the specified number of times.

image
  • Retry conditions for HTTP requests:

    • 5xx: The backend service returns a 5xx status code, or a disconnection, reset, or read timeout event occurs.

      Note

      The 5xx condition includes the connect-failure and refused-stream conditions.

    • reset: A disconnection, reset, or read timeout event occurs.

    • connect-failure: The request failed due to a disconnection.

    • refused-stream: The backend server returns the REFUSED_STREAM status code.

    • retriable-status-codes: The backend server returns one of the specified status codes.

      Note

      You can specify the status codes only if you select retriable-status-codes as a retry condition.

  • Retry conditions for gRPC requests:

    • cancelled: The CANCELLED status code is contained in the header of the response from the backend gRPC service.

    • deadline-exceeded: The DEADLINE_EXCEEDED status code is contained in the header of the response from the backend gRPC service.

    • internal: The INTERNAL status code is contained in the header of the response from the backend gRPC service.

    • resource-exhausted: The RESOURCE_EXHAUSTED status code is contained in the header of the response from the backend gRPC service.

    • unavailable: The UNAVAILABLE status code is contained in the header of the response from the backend gRPC service.

Configure a retry policy

  1. Log on to the Cloud-native API Gateway console.

  2. In the left-side navigation pane, click API. In the top navigation bar, select a region.

  3. Click the target API. On the API details page, click the name of the target route. Click the Configure Policy tab and click Retry on the left.

  4. On the Retry tab, configure the parameters and click Save.

    Parameter

    Description

    Enable

    Specifies whether to enable the retry policy.

    • If you turn on the switch, the retry policy takes effect.

    • If you turn off the switch, the retry policy does not take effect.

    Note

    If you disable the retry policy, the gateway automatically retries a failed request for a maximum of two times based on the following conditions: connect-failure, refused-stream, unavailable, cancelled, and retriable-status-codes.

    Retry Times

    The maximum number of retries for a failed request. You can set this parameter to an integer ranging from 0 to 10. We recommend that you set this parameter to 0, 1, or 2.

    Note

    If you set this parameter to 0, failed requests are not retried.

    Retry Conditions

    The condition that triggers retries. You can select one or more conditions. For more information, see the "Retry conditions" section in this topic.

    Retry Status Code

    The HTTP status codes that trigger retries. You can specify one or more HTTP status codes.

    Note

    This parameter is valid only if you select retriable-status-codes for the Retry Conditions parameter.Retry Status Code

    After the retry policy is created and enabled, you can check whether the retry policy takes effect based on your business requirements.