Skip to content

Commit 169f8f4

Browse files
committed
[APIM] Circuit breaker in backend
1 parent a491431 commit 169f8f4

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

articles/api-management/backends.md

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ editor: ''
88

99
ms.service: api-management
1010
ms.topic: article
11-
ms.date: 09/21/2021
11+
ms.date: 07/24/2023
1212
ms.author: danlep
1313
ms.custom:
1414
---
@@ -26,12 +26,9 @@ API Management also supports using other Azure resources as an API backend, such
2626
* A [Service Fabric cluster](how-to-configure-service-fabric-backend.md).
2727
* A custom service.
2828

29-
Custom backends require extra configuration to authorize the credentials of requests to the backend service and define API operations. Configure and manage custom backends in the Azure portal, or using Azure APIs or tools.
29+
Custom backends require extra configuration, for example, to authorize the credentials of requests to the backend service and define API operations. Configure and manage custom backends in the Azure portal, or using Azure APIs or tools.
3030

31-
After creating a backend, you can reference the backend in your APIs. Use the [`set-backend-service`](set-backend-service-policy.md) policy to redirect an incoming API request to the custom backend instead of the default backend for that API.
32-
33-
> [!NOTE]
34-
> When you use the `set-backend-service` policy to redirect requests to a custom backend, refer to the backend by its name (`backend-id`), not by its URL.
31+
After creating a backend, you can reference the backend in your APIs. Use the [`set-backend-service`](set-backend-service-policy.md) policy to direct an incoming API request to the custom backend. If you already configured a backend web service for an API, you can use the `set-backend-service` policy to redirect the request to a custom backend instead of the default backend web service configured for that API.
3532

3633
## Benefits of backends
3734

@@ -41,6 +38,94 @@ A custom backend has several benefits, including:
4138
* Easily used by configuring a transformation policy on an existing API.
4239
* Takes advantage of API Management functionality to maintain secrets in Azure Key Vault if [named values](api-management-howto-properties.md) are configured for header or query parameter authentication.
4340

41+
42+
## Circuit breaker property (preview)
43+
44+
Starting in API version 2023-03-01 preview, API Management exposes a [circuit breaker](/rest/api/apimanagement/current-preview/backend/create-or-update?tabs=HTTP#backendcircuitbreaker) property in the backend resource to protect a backend service from being overwhelmed by too many requests.
45+
46+
* The circuit breaker property defines rules to trip the circuit breaker, such as the number or percentage of failure conditions during a defined time interval and a range of status codes that indicate failures.
47+
* When the circuit breaker trips, API Management stops sending requests to the backend service for a defined time, and returns a 503 Service Unavailable response to the client.
48+
* After the configured trip duration, the circuit resets and traffic resumes to the backend.
49+
50+
The backend circuit breaker is an implementation of the [circuit breaker pattern](/azure/architecture/patterns/circuit-breaker) to allow the backend to recover from overload situations. It augments general [rate-limiting](rate-limit-by-key.md) and [concurrency-limiting](limit-concurrency.md) policies that you can implement to protect the API Management gateway and your backend services.
51+
52+
### Example
53+
54+
Use the API Management REST API or a Bicep or ARM template to configure a circuit breaker in a backend. In the following example, the circuit breaker trips when there are three or more 5xx status codes indicating server errors in a day. The circuit breaker resets after one hour.
55+
56+
#### [Bicep](#tab/bicep)
57+
58+
Include a snippet similar to the following in your Bicep template:
59+
60+
```bicep
61+
resource symbolicname 'Microsoft.ApiManagement/service/backends@2023-03-01-preview' = {
62+
name: 'myBackend'
63+
parent: resourceSymbolicName
64+
properties: {
65+
circuitBreaker: {
66+
rules: [
67+
{
68+
failureCondition: {
69+
count: 3
70+
errorReasons: [
71+
'Server errors'
72+
]
73+
interval: 'P1D'
74+
percentage: int
75+
statusCodeRanges: [
76+
{
77+
max: 500
78+
min: 599
79+
}
80+
]
81+
}
82+
name: 'myBreakerRule'
83+
tripDuration: 'P1H'
84+
}
85+
]
86+
}
87+
}
88+
[...]
89+
}
90+
```
91+
92+
#### [ARM](#tab/arm)
93+
94+
Include a JSON snippet similar to the following in your ARM template:
95+
96+
```JSON
97+
{
98+
"type": "Microsoft.ApiManagement/service/backends",
99+
"apiVersion": "2023-03-01-preview",
100+
"name": "myBackend",
101+
"properties": {
102+
"circuitBreaker": {
103+
"rules": [
104+
{
105+
"failureCondition": {
106+
"count": "3",
107+
"errorReasons": [ "Server errors" ],
108+
"interval": "P1D",
109+
"statusCodeRanges": [
110+
{
111+
"max": "500",
112+
"min": "599"
113+
}
114+
]
115+
},
116+
"name": "myBreakerRule",
117+
"tripDuration": "P1H"
118+
}
119+
]
120+
},
121+
}
122+
[...]
123+
}
124+
```
125+
126+
---
127+
128+
44129
## Limitation
45130

46131
For **Developer** and **Premium** tiers, an API Management instance deployed in an [internal virtual network](api-management-using-with-internal-vnet.md) can throw HTTP 500 `BackendConnectionFailure` errors when the gateway endpoint URL and backend URL are the same. If you encounter this limitation, follow the instructions in the [Self-Chained API Management request limitation in internal virtual network mode](https://techcommunity.microsoft.com/t5/azure-paas-blog/self-chained-apim-request-limitation-in-internal-virtual-network/ba-p/1940417) article in the Tech Community blog.

0 commit comments

Comments
 (0)