Code Room
Code reviewMediumcr-g507
Subject Circuit breakerLevel Senior~18 minCommon in Code quality & review interviewsIndustries Software development, Technology

Question

Review this Java breaker that opens after 5 failures and is supposed to protect a downstream.

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 reviewjava
class Breaker {    private int failures = 0;    <T> T call(Supplier<T> fn) {        if (failures >= 5) throw new BreakerOpenException();        try {            T r = fn.get();            return r;            // success: counter untouched        } catch (RuntimeException e) {            failures++;            throw e;        }    }}
Run or narrate your approach, then ask the coach.