Cloud API Management Circuit Breaker Service Adapter
This adapter allows you to apply circuit breakers to your APIs to protect your backend systems. It provides a fault-tolerance mechanism that monitors service health and automatically blocks requests to failing services, preventing cascading failures.
Simply put, when a service fails, the circuit breaker trips to protect your backend system from crashing by immediately returning an error response while the service is down, thereby maintaining core functionality during the failure. This helps prevent system-wide outages, eliminates resource waste on failing services, and enables fast failure responses rather than timeouts.
Description
-
This feature secures your backend services by tripping when failure conditions are met within the defined Error threshold and Observation window, and by waiting for the defined recovery time period (circuit open duration) to allow the backend to recover.
-
Circuit breaker triggers under the following conditions:
-
Slow call response: The adapter compares the configured API response time with the actual response time.
For example, if the configured API response time is 2000 ms and the actual response exceeds that threshold (crossing the percentage threshold for slow calls), the circuit breaker trips to prevent a system failure.
-
Error response: This is the defined failure rate (threshold) relative to the number of API requests in the observation window.
For example, if the API error threshold is set to 50% and the observation window contains 10 requests, the circuit breaker trips at the end of the window when 5 or more requests fail (50% or more) in the window, temporarily stopping further API calls to proceed to the backend and preventing system failure.
-
-
The following are the states of a circuit breaker:
-
Closed: When the circuit breaker is closed, calls can proceed to the backend.
-
Open: The circuit breaker has tripped open due to errors or slow calls, preventing calls from reaching the backend and returning a 503 Service Unavailable response.
-
Half-open: Only some calls are allowed to the backend. The permit-half-open and min-calls configuration can be adjusted according to the client’s traffic and requirements in this state.
-
-
The adapter monitors incoming client requests as they pass through the API gateway and to the backend service. The adapter keeps a count of the observation window, the number of failed, successful, and slow calls. If any slow calls or the error threshold is exceeded, the adapter opens the circuit, and calls are not sent to the backend until the open duration has lapsed.
-
When the circuit is open, any incoming client requests to the API gateway return a 503 Service Unavailable response, and no requests from the API gateway reach the backend service.
-
The circuit remains open until the recovery threshold configured by the adapter is reached. For example, if the adapter-configured recovery threshold is set to 1 minute, after 1 minute, incoming client requests to the API gateway will be forwarded to the backend service only if the backend responds successfully, thereby closing the circuit.
-
When the circuit is closed, an observation window of 5 incoming client requests (or calls) is monitored. Suppose the configured error threshold is 50%. If 3 or more calls fail, the circuit returns to the open state; otherwise, it goes to the complete close state, and the observation window resets to the configured
obs-window.