[Proposal] Circuit Breaker for HTTP Client #59106
Unanswered
joy-deploy
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone,
I'd like to propose adding an optional circuit breaker to the HTTP client.
The problem is simple: when an external API goes down,
retry()keeps sending requests to it. Each one waits for the timeout, workers stack up, and the failing service ends up affecting unrelated parts of your app.A circuit breaker counts recent failures for a given service. After a threshold it stops making requests and throws immediately. After a cooldown it lets one request through to test if the service is back.
Other frameworks have this built in (Resilience4j, Polly, gobreaker). I think it fits naturally in Laravel's HTTP client next to
retry()andtimeout().I have the implementation ready, about 100 lines. Failure counting goes through
RateLimiter::hit()for atomic increments. Half-open probe locking usesCache::lock()like the scheduler does withwithoutOverlapping. If cache is down it fails open.Trips on 5xx and
ConnectionExceptionby default, not 4xx. There's awhenFailedcallback for custom logic.Scope is intentionally small. No sliding windows or error-rate calculations, just a counter with time decay like
RateLimiter.Anyone else running into this? How are you handling it? Happy to put up a PR if there's interest.
Beta Was this translation helpful? Give feedback.
All reactions