Documentation Index
Fetch the complete documentation index at: https://mintlify.com/traefik/traefik/llms.txt
Use this file to discover all available pages before exploring further.
CircuitBreaker Middleware
Don’t Waste Time Calling Unhealthy Services The circuit breaker protects your system from stacking requests to unhealthy services, preventing cascading failures.How It Works
When your system is healthy, the circuit is closed (normal operations). When your system becomes unhealthy, the circuit opens, and requests are handled by a fallback mechanism instead of being forwarded to the service. The circuit breaker constantly monitors services to assess health.The CircuitBreaker only analyzes what happens after its position within the middleware chain. What happens before has no impact on its state.
Configuration Examples
Latency-Based Circuit Breaker
Error Rate Circuit Breaker
Circuit States
Closed
Normal operation. The circuit breaker collects metrics and evaluates the expression at eachcheckPeriod interval.
Open
Fallback mechanism is active. Returns HTTP 503 (or configuredresponseCode) for fallbackDuration.
Recovering
Gradually increases traffic to the service forrecoveryDuration. If successful, the circuit closes. If the service fails, the circuit opens again.
Configuration Options
Expression Metrics
Expression that triggers the circuit breaker when matched. Can use:
NetworkErrorRatio()- Network error ratioResponseCodeRatio(from, to, dividedByFrom, dividedByTo)- Status code ratioLatencyAtQuantileMS(quantile)- Latency at quantile in milliseconds
NetworkErrorRatio
Triggers when network errors reach a threshold:ResponseCodeRatio
Triggers based on HTTP status code ratios:sum(to -> from) / sum(dividedByFrom -> dividedByTo)
from is inclusive, to is exclusive.LatencyAtQuantileMS
Triggers when latency exceeds threshold:Quantile value must be a floating point number (with
.0).Combining Metrics
Use&& (AND) or || (OR) operators:
Timing Options
Interval between condition checks when in standby state.
Duration to wait before attempting recovery from tripped state.
Duration to try recovering once in recovering state.
Fallback Options
HTTP status code returned while circuit is open.