
How a “Kind of Working” Payment Gateway Made Me Write This Circuit Breaker
I got bored and wrote a circuit breaker A few years ago I was working at a fintech company. We had an integration with a payment gateway. Critical one — money literally depended on it. One day it started behaving weird. Not down. Not healthy. Just slow enough to destroy everything . Requests were hanging. Threads piling up. Retries amplifying the problem. Other services started lagging. The gateway was still responding — just slowly enough to kill us. We needed a circuit breaker. We didn't have one. So we hacked something together in production. Ugly, tightly coupled, impossible to test. Fast forward to now — I built the circuit breaker I wish we had back then. Show me the code breaker , _ := circuitbreaker . New ( "stripe" , cb . WithConsecutiveFailures ( 5 ), cb . WithOpenTimeout ( 30 * time . Second ), ) err := breaker . Execute ( ctx , func () error { return stripeClient . Charge ( amount ) }) if errors . Is ( err , cb . ErrCircuitOpen ) { // fallback or fail fast } That's it. Wrap
Continue reading on Dev.to
Opens in a new tab



