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

Question

Review this Go circuit breaker wrapping a downstream call.

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 reviewgo
type Breaker struct {    mu       sync.Mutex    failures int    open     bool} func (b *Breaker) Call(fn func() error) error {    b.mu.Lock(); o := b.open; b.mu.Unlock()    if o {        return errors.New("circuit open")    }    err := fn()    b.mu.Lock(); defer b.mu.Unlock()    if err != nil {        b.failures++        if b.failures >= 5 {            b.open = true        }    }    return err}
Run or narrate your approach, then ask the coach.