Add circuit breaker to prevent cascading backend failuresFeature/circuit breaker#6
Open
Prithvish7 wants to merge 10 commits intolugnitdgp:mainfrom
Open
Add circuit breaker to prevent cascading backend failuresFeature/circuit breaker#6Prithvish7 wants to merge 10 commits intolugnitdgp:mainfrom
Prithvish7 wants to merge 10 commits intolugnitdgp:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, Routrix relies on interval-based health checks to mark backend availability. However, in real-world systems, a backend may remain alive but still fail at the request level due to: timeouts, connection errors, slow responses
In such cases, continuing to route traffic to the backend can cause cascading failures. The circuit breaker addresses this gap by reacting immediately to runtime failures.
Key Changes:
Request-Level Failure Tracking
⦁ Failures are tracked directly at L4 (TCP) and L7 (HTTP) proxy layers.
⦁ Each backend maintains FailureCount, LastFailure, and LastSuccess.
Circuit Breaker States
⦁ Implemented three states: CLOSED, OPEN, HALF_OPEN.
⦁ Backends transition to OPEN after repeated failures.
⦁ After a cooldown period, HALF_OPEN allows limited retry.
⦁ Successful requests restore the backend to CLOSED.
Routing Protection
⦁ All routing algorithms skip backends in OPEN state.
⦁ Prevents sending traffic to unstable backends immediately.
Observability
⦁ Circuit state, failure counts, and decision logs are exposed via /status.
Verification & Demo
Verified by intentionally stopping a backend and generating traffic.
Observed:
🎥 Demo video attached (shows failure and recovery flow).
https://drive.google.com/file/d/1mP9mJpjOoO-Tib98SKKAS9B-uorpkYF5/view?usp=drive_link