
Circuit breaker in Go: surviving exchange outages
Binance announces maintenance at 2am. Your service keeps hammering it at 10 req/sec for 30 minutes. Result: 18,000 lost requests, goroutines piling up as each call waits for its timeout, and memory climbing steadily until the scheduler starts to struggle. A circuit breaker takes 50 lines to write. Binance maintenance is inevitable. OKEx returns random 503s. Coinbase rate limits without warning. Crypto exchanges have SLAs that would make any ops engineer used to AWS flinch. If your service consumes several of them, resilience is not optional. The previous article covered the rate limiter: how to avoid exceeding an API's quota. This pattern answers a different question — what to do when the API is down, not just slow? The three states of a circuit breaker A circuit breaker is a three-state machine. The analogy with an electrical breaker is accurate: when too many errors occur, the circuit opens and cuts the flow. Closed — normal state. Requests pass through. Failures are counted. As long
Continue reading on Dev.to
Opens in a new tab



