Skip to content

Circuit Breaker for Stellar Client #183

@mftee

Description

@mftee

Implement a circuit breaker pattern for the StellarClient to prevent cascading failures when the Stellar Horizon API is unavailable. The circuit breaker should automatically open after repeated failures and recover after a timeout.

Requirements:

  • Implement a CircuitBreaker struct with states: Closed, Open, HalfOpen
  • Configuration via CircuitBreakerConfig:
    pub struct CircuitBreakerConfig {
        pub failure_threshold: u32,   // failures before opening
        pub success_threshold: u32,   // successes in HalfOpen before closing
        pub timeout_secs: u64,        // seconds before trying HalfOpen
    }
  • Wrap StellarClient calls: if the breaker is Open, return an error immediately without making an HTTP request
  • After timeout_secs, transition to HalfOpen and allow one request through
  • If that request succeeds success_threshold times, close the circuit; if it fails, reopen it
  • Expose circuit state in the GET /health response
  • Use std::sync::atomic types for thread-safe state management

Acceptance Criteria:

  • Circuit opens after failure_threshold consecutive failures
  • While open, requests fail immediately with a specific CircuitOpenError
  • Unit tests for all three state transitions
  • Health endpoint accurately reflects circuit state

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions