How to Implement a Distributed Circuit Breaker

If a payment API starts timing out, every checkout request sits and waits for the full timeout before failing, holding a worker the whole time. A circuit breaker stops that by failing fast once enough recent calls have failed.

That is easy in one process, but once your app runs on more than one instance, each instance keeps its own record and has to get burned separately before it reacts, so the struggling API takes far more traffic than it should before anything trips.

The basic pattern, then what has to change when the state is shared between instances. Code is TypeScript and Redis (Lua).

submitted by /u/OtherwisePush6424
[link] [留言]