Circuit Breaker
Circuit Breaker Policy
Policy name |
|
Summary |
Prevents an upstream from receiving too many requests or connections |
Category |
Quality of Service |
First Flex Gateway version available |
v1.9.0 |
Returned Status Codes |
503 - Service Unavailable |
Summary
The Circuit Breaker policy prevents upstream services from receiving too many requests or connections at a time. If the defined maximums are reached, Flex Gateway returns a 503 - Service Unavailable
error.
For Managed Flex Gateways or Connected Mode, each API instance has its own independent limit when requesting the same upstream, allowing each to use the full maximum. In Local Mode, the limits are shared among different API instances, so they must all adhere to the same upstream maximum. For all modes, maximums are not distributed across replicas; each Gateway can use the full maximum.
The Circuit Breaker policy is an extension of the Envoy upstream clusters circuit breaking feature. To learn more about the Envoy’s circuit breaking, see Circuit Breaking in the Envoy documentation.
Configuring Policy Parameters
Flex Gateway Local Mode
In Local Mode, you apply the Circuit Breaker policy to your API via declarative configuration files. Refer to the following policy definition and table of parameters:
apiVersion: gateway.mulesoft.com/v1alpha1 kind: PolicyBinding metadata: name: upstream-policy spec: targetRef: Kind: Service name: upstream policyRef: name: circuit-breaker-flex config: thresholds: maxConnections: <number> // OPTIONAL maxPendingRequests: <number> // OPTIONAL maxRequests: <number> // OPTIONAL maxRetries: <number> // OPTIONAL maxConnectionPools: <number> // OPTIONAL
For Local Mode, the limits are not independent, so different API instances share the maximums for an upstream. |
Parameter | Required or Optional | Description |
---|---|---|
|
Optional |
Maximum number of connections per API to an upstream. |
|
Optional |
Maximum number of queued requests while waiting for a connection. |
|
Optional |
Maximum number of outstanding requests to an upstream. |
|
Optional |
Maximum number of outstanding retries. |
|
Optional |
Maximum number of connection pools concurrently initiated to an upstream. |
Resource Configuration Example
This example defines a policy of three requests every six seconds:
apiVersion: gateway.mulesoft.com/v1beta1 kind: Configuration metadata: name: circuit-breaker namespace: test-ns spec: circuitBreaker: thresholds: maxConnections: 1 maxPendingRequests: 1 maxRequests: 1 maxRetries: 1 maxConnectionPools: 1
Flex Gateway Connected Mode
When you apply the Rate Limiting policy to your API from the UI, you can configure the following parameters:
Parameter | Required or Optional | Description |
---|---|---|
Maximum connections |
Optional |
Maximum number of connections per API to an upstream. |
Maximum pending requests |
Optional |
Maximum number of queued requests while waiting for a connection. |
Maximum requests |
Optional |
Maximum number of outstanding requests to an upstream. |
Maximum retries |
Optional |
Maximum number of outstanding retries. |
Maximum connection pools |
Optional |
Maximum number of connection pools concurrently initiated to an upstream. |
For Managed Flex Gateways or Connected Mode, each API instance has its own independent limit when requesting the same upstream, allowing each to use the full maximum. |