The circuit breaker is a design pattern used to detect failures and encapsulate the logic that prevents a failure from recurring continuously. It operates similarly to an electrical circuit breaker, which "trips" or opens the circuit when a failure is detected. In a software application, a circuit breaker acts as a proxy that executes remote services while monitoring them for failures, which can manifest as exceptions or timeouts. When the number of failures exceeds a predetermined threshold within a specified time period, the circuit breaker shuts off access to the affected service.

Developing a contingency plan is essential for managing situations when a faulty service becomes unreachable. This plan may involve increasing the retry interval, rerouting users to an alternative service, or reducing functionality during the period of unavailability. Such measures can prevent the application from repeatedly attempting operations that are likely to fail, allowing it to continue functioning without waiting for the issue to be resolved. Additionally, the circuit breaker pattern enables the application to detect when the fault has been fixed. If the problem appears to be resolved, the application can attempt to invoke the operation again.

Roxy-WI provides a great opportunity to implement Circuit Breaking with just a few clicks.

Go to the HAProxy => Add proxy section and select the tab depending on what you wish to create: Listener or Backend. Then, click Show advanced settings.

Roxy-WI Circuit Breaking

Check the Circuit Breaking box and select the parameters based on the provided description.

Roxy-WI Circuit Breaking

Parameter: Description:
observe layer7 Monitors live traffic for HTTP errors.
observe layer4 Monitors live traffic for TCP errors.
error-limit 50 Specifies the number of errors that constitute the threshold.
on-error Defines the action to be taken when the threshold is exceeded.
On-error action: Description:
mark-down Marks the service as down.
fastinter Forces a fast interval for health checks.
fail-check Simulates a failed health check and also forces a fast interval (default).
sudden-death Simulates a pre-fatal failed health check; one additional failed check will mark the server as down, and it also forces a fast interval.