Circuit Breaker Policy | MuleSoft Documentation
# Circuit Breaker Policy
**Policy name** |  Circuit Breaker  
---|---  
Prevents an upstream from receiving too many requests or connections  
Quality of Service  
**First Flex Gateway version available**  
**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 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  
---|---|---  
`maximumConnections` |  Maximum number of connections per API to an upstream.  
`maximumPendingRequests` |  Maximum number of queued requests while waiting for a connection.  
`maximumRequests` |  Maximum number of outstanding requests to an upstream.  
`maximumRetries` |  Maximum number of outstanding retries.  
`maximumConnectionPools` |  Maximum number of connection pools concurrently initiated to an upstream.  
#### Resource Configuration Example
This example defines a policy that supports a maximum of one request at a time:
```
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
```

### Managed Flex Gateway and Flex Gateway Connected Mode
When you apply the policy to your API instance from the UI, the following parameters are displayed:
Parameter | Required or Optional | Description  
---|---|---  
Maximum connections |  Maximum number of connections per API to an upstream.  
Maximum pending requests |  Maximum number of queued requests while waiting for a connection.  
Maximum requests |  Maximum number of outstanding requests to an upstream.  
Maximum retries |  Maximum number of outstanding retries.  
Maximum connection pools |  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.   
---