Skip to content

Ambiguities in Challenge 20: Circuit Breaker #637

@asarkar

Description

@asarkar
type Config struct {
    MaxRequests      uint32        // Max requests allowed in half-open state
    Interval         time.Duration // Statistical window for closed state
    Timeout          time.Duration // Time to wait before half-open
    ReadyToTrip      func(Metrics) bool // Function to determine when to trip
    OnStateChange    func(name string, from State, to State) // State change callback
}

While implementing the Circuit Breaker challenge, I found some unclear aspects in the Config struct.
For reference, I compared the design to the Azure Circuit Breaker pattern to clarify expected behavior.

Issues

  • MaxRequests - Should be renamed to HalfOpenMaxRequests. If cb.halfOpenRequests is equal to this value, say n, the state changes to closed. The error ErrTooManyRequests doesn't make sense here; in the half-open state, even if one request fails, the CB moves to the open state. If n number of requests all succeed, the CB transitions to closed state. At no time, the CB will receive more than n requests in the half-open state.

  • Interval – The comment "Statistical window for closed state" is unclear. It seems to represent the time window used to measure failures in the closed state. Suggest renaming the field and/or updating the comment.

  • Timeout – The period the breaker stays open before moving to half-open. Clear enough.

  • ReadyToTrip – Allowing the client to decide when to trip may lead to abuse (e.g., always returning false). This logic should ideally be internal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions