Skip to content

Commit d5ca10c

Browse files
author
Jill Grant
authored
Merge pull request #246213 from dlepow/back
[APIM] Circuit breaker in backend
2 parents 2f7989d + 5a359e0 commit d5ca10c

File tree

1 file changed

+95
-7
lines changed

1 file changed

+95
-7
lines changed

articles/api-management/backends.md

Lines changed: 95 additions & 7 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: 08/16/2023
1212
ms.author: danlep
1313
ms.custom:
1414
---
@@ -17,7 +17,7 @@ ms.custom:
1717

1818
A *backend* (or *API backend*) in API Management is an HTTP service that implements your front-end API and its operations.
1919

20-
When importing certain APIs, API Management configures the API backend automatically. For example, API Management configures the backend when importing:
20+
When importing certain APIs, API Management configures the API backend automatically. For example, API Management configures the backend web service when importing:
2121
* An [OpenAPI specification](import-api-from-oas.md).
2222
* A [SOAP API](import-soap-api.md).
2323
* Azure resources, such as an HTTP-triggered [Azure Function App](import-function-app-as-api.md) or [Logic App](import-logic-app-as-api.md).
@@ -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+
API Management supports custom backends so you can manage the backend services of your API. Use custom backends, for example, to authorize the credentials of requests to the backend service. 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,97 @@ 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+
## Circuit breaker (preview)
42+
43+
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.
44+
45+
* 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.
46+
* 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.
47+
* After the configured trip duration, the circuit resets and traffic resumes to the backend.
48+
49+
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-policy.md) and [concurrency-limiting](limit-concurrency-policy.md) policies that you can implement to protect the API Management gateway and your backend services.
50+
51+
### Example
52+
53+
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.
54+
55+
#### [Bicep](#tab/bicep)
56+
57+
Include a snippet similar to the following in your Bicep template:
58+
59+
```bicep
60+
resource symbolicname 'Microsoft.ApiManagement/service/backends@2023-03-01-preview' = {
61+
name: 'myBackend'
62+
parent: resourceSymbolicName
63+
properties: {
64+
url: 'https://mybackend.com'
65+
protocol: 'http'
66+
circuitBreaker: {
67+
rules: [
68+
{
69+
failureCondition: {
70+
count: 3
71+
errorReasons: [
72+
'Server errors'
73+
]
74+
interval: 'P1D'
75+
percentage: int
76+
statusCodeRanges: [
77+
{
78+
min: 500
79+
max: 599
80+
}
81+
]
82+
}
83+
name: 'myBreakerRule'
84+
tripDuration: 'PT1H'
85+
}
86+
]
87+
}
88+
}
89+
[...]
90+
}
91+
```
92+
93+
#### [ARM](#tab/arm)
94+
95+
Include a JSON snippet similar to the following in your ARM template:
96+
97+
```JSON
98+
{
99+
"type": "Microsoft.ApiManagement/service/backends",
100+
"apiVersion": "2023-03-01-preview",
101+
"name": "myBackend",
102+
"properties": {
103+
"url": "https://mybackend.com",
104+
"protocol": "http",
105+
"circuitBreaker": {
106+
"rules": [
107+
{
108+
"failureCondition": {
109+
"count": "3",
110+
"errorReasons": [ "Server errors" ],
111+
"interval": "P1D",
112+
"statusCodeRanges": [
113+
{
114+
"min": "500",
115+
"max": "599"
116+
}
117+
]
118+
},
119+
"name": "myBreakerRule",
120+
"tripDuration": "PT1H"
121+
}
122+
]
123+
}
124+
}
125+
[...]
126+
}
127+
```
128+
129+
---
130+
131+
44132
## Limitation
45133

46134
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)