Code Room
Code reviewHardcr-g497
Subject Circuit breakerLevel Senior–Staff~20 minCommon in Code quality & review interviewsIndustries Software development, Technology

Question

Review this Python circuit breaker. When open, after a cooldown it moves to half-open and lets calls through to test recovery.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
class Breaker:    def call(self, fn):        if self.state == "open":            if time.time() - self.opened_at >= self.cooldown:                self.state = "half_open"            else:                raise BreakerOpen()        try:            r = fn()            self.state = "closed"; self.failures = 0            return r        except Exception:            self.failures += 1            self.state = "open"; self.opened_at = time.time()            raise
Run or narrate your approach, then ask the coach.