🛡️ Error Handling & Resilience

Enterprise-grade error handling with circuit breakers, retry strategies, and comprehensive fallback mechanisms

⚡ CIRCUIT BREAKERS 🔄 RETRY STRATEGIES 🎯 99% UPTIME

📋 Quick Navigation

🎯 Resilience Overview ⚡ Circuit Breakers 🔄 Retry Strategies 🎯 Fallback Systems 📊 Health Monitoring 🔧 Auto Recovery

🎯 Enterprise Resilience Overview

The Error Handling & Resilience System delivers 99% uptime reliability through sophisticated failure detection, intelligent retry strategies, and comprehensive fallback mechanisms that ensure continuous ESG intelligence availability.

🚀 Resilience Architecture

⚡ Circuit Breaker Pattern

  • Automatic Failure Detection: Real-time API health monitoring
  • Fast Fail: Immediate response to service degradation
  • Self-Healing: Automatic recovery testing and restoration
  • Graceful Degradation: Maintain functionality during failures

🔄 Intelligent Retry Logic

  • Exponential Backoff: Progressive delay increases
  • Jitter: Randomized timing to prevent thundering herd
  • Max Attempts: Configurable retry limits per API source
  • Error Classification: Retry only on retryable errors

⚡ Circuit Breaker System

Circuit breakers provide automatic failure detection and isolation, preventing cascading failures and ensuring system stability during API outages or degradation.

🔌 Circuit Breaker States

CLOSED Normal Operation

  • Request Flow: All requests pass through normally
  • Error Tracking: Monitor failure rate and response times
  • Threshold Check: Watch for failure rate exceeding 50%
  • Performance: No additional latency introduced

OPEN Failure Protection

  • Request Blocking: All requests fail fast immediately
  • Fallback Activation: Alternative data sources engaged
  • Recovery Timer: Wait period before testing recovery
  • Resource Protection: Prevent resource exhaustion

HALF-OPEN Recovery Testing

  • Limited Testing: Single request to test service health
  • Success Recovery: Return to CLOSED state if successful
  • Failure Handling: Return to OPEN state if failed
  • Gradual Recovery: Progressive load increase on success
▶ // Show code example click to expand
// Circuit Breaker Implementation class CircuitBreaker { constructor(options = {}) { this.failureThreshold = options.failureThreshold || 5; this.recoveryTimeout = options.recoveryTimeout || 60000; // 1 minute this.monitoringPeriod = options.monitoringPeriod || 10000; // 10 seconds this.state = 'CLOSED'; this.failures = 0; this.lastFailureTime = null; this.successCount = 0; } async execute(operation) { if (this.state === 'OPEN') { if (this.shouldAttemptReset()) { this.state = 'HALF_OPEN'; } else { throw new Error('Circuit breaker is OPEN'); } } try { const result = await operation(); this.onSuccess(); return result; } catch (error) { this.onFailure(); throw error; } } onSuccess() { this.failures = 0; if (this.state === 'HALF_OPEN') { this.state = 'CLOSED'; } } onFailure() { this.failures++; this.lastFailureTime = Date.now(); if (this.failures >= this.failureThreshold) { this.state = 'OPEN'; } } shouldAttemptReset() { return Date.now() - this.lastFailureTime >= this.recoveryTimeout; } }

🎯 Per-API Circuit Breaker Configuration

🏦 Financial APIs (Alpha Vantage, FMP)

  • Failure Threshold: 3 failures in 5 minutes
  • Recovery Timeout: 2 minutes
  • Monitoring Period: 5 minutes rolling window
  • Fallback: Cached data + alternative sources

🌱 Government APIs (EPA, World Bank)

  • Failure Threshold: 5 failures in 10 minutes
  • Recovery Timeout: 5 minutes
  • Monitoring Period: 10 minutes rolling window
  • Fallback: Extended cache TTL + graceful degradation

📊 ESG APIs (Yahoo Finance)

  • Failure Threshold: 4 failures in 8 minutes
  • Recovery Timeout: 3 minutes
  • Monitoring Period: 8 minutes rolling window
  • Fallback: Community data + estimated scores

🔄 Intelligent Retry Strategies

Sophisticated retry mechanisms with exponential backoff, jitter, and intelligent error classification ensure optimal recovery while preventing system overload.

🧠 Exponential Backoff with Jitter

📈 Backoff Strategy

  • Base Delay: 1 second initial wait
  • Multiplier: 2x increase per retry
  • Maximum Delay: 60 seconds cap
  • Jitter: ±25% randomization to prevent thundering herd

🎯 Error Classification

  • Retryable: Network timeouts, 5xx errors, rate limits
  • Non-retryable: 4xx client errors, authentication failures
  • Circuit Breaker: Persistent failures trigger breaker
  • Immediate Fail: Invalid requests fail fast
▶ // Show code example click to expand
// Intelligent Retry Strategy Implementation class RetryStrategy { constructor(options = {}) { this.maxAttempts = options.maxAttempts || 3; this.baseDelay = options.baseDelay || 1000; // 1 second this.maxDelay = options.maxDelay || 60000; // 60 seconds this.jitterFactor = options.jitterFactor || 0.25; // ±25% } async executeWithRetry(operation, context = {}) { let lastError; for (let attempt = 1; attempt <= this.maxAttempts; attempt++) { try { return await operation(); } catch (error) { lastError = error; // Don't retry non-retryable errors if (!this.isRetryable(error)) { throw error; } // Don't retry on last attempt if (attempt === this.maxAttempts) { break; } const delay = this.calculateDelay(attempt); await this.sleep(delay); console.log(`Retry attempt ${attempt}/${this.maxAttempts} after ${delay}ms delay`); } } throw lastError; } calculateDelay(attempt) { // Exponential backoff: baseDelay * (2^(attempt-1)) let delay = this.baseDelay * Math.pow(2, attempt - 1); // Apply maximum delay cap delay = Math.min(delay, this.maxDelay); // Add jitter to prevent thundering herd const jitter = delay * this.jitterFactor * (Math.random() - 0.5); return Math.max(0, delay + jitter); } isRetryable(error) { // Network errors if (error.code === 'ENOTFOUND' || error.code === 'ECONNRESET') { return true; } // HTTP errors if (error.status) { // Rate limiting if (error.status === 429) return true; // Server errors (5xx) if (error.status >= 500) return true; // Service unavailable if (error.status === 503) return true; // Client errors (4xx) are not retryable if (error.status >= 400 && error.status < 500) return false; } // Timeout errors if (error.message && error.message.includes('timeout')) { return true; } return false; } sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } }

⚙️ Source-Specific Retry Configuration

📈 Alpha Vantage

  • Max Attempts: 3
  • Base Delay: 2 seconds
  • Rate Limit Handling: 60-second backoff
  • Timeout: 15 seconds

🌱 EPA Envirofacts

  • Max Attempts: 5
  • Base Delay: 1 second
  • Rate Limit Handling: Not applicable
  • Timeout: 30 seconds

📊 Yahoo Finance ESG

  • Max Attempts: 4
  • Base Delay: 3 seconds
  • Rate Limit Handling: 120-second backoff
  • Timeout: 20 seconds

🏦 World Bank

  • Max Attempts: 3
  • Base Delay: 1 second
  • Rate Limit Handling: Not applicable
  • Timeout: 45 seconds

🏢 OpenFIGI

  • Max Attempts: 2
  • Base Delay: 1 second
  • Rate Limit Handling: 30-second backoff
  • Timeout: 10 seconds

📰 FMP

  • Max Attempts: 3
  • Base Delay: 1 second
  • Rate Limit Handling: 30-second backoff
  • Timeout: 12 seconds

🎯 Comprehensive Fallback Systems

Multi-level fallback mechanisms ensure continuous ESG intelligence availability through cache utilization, alternative sources, and graceful degradation strategies.

🔄 Fallback Cascade Strategy

1️⃣ Primary API

Direct API call to primary source

→

2️⃣ Fresh Cache

Recent cached data if available

→

3️⃣ Alternative Source

Backup API with similar data

→

4️⃣ Stale Cache

Expired cache with warning

→

5️⃣ Graceful Degradation

Estimated values with disclaimer

▶ // Show code example click to expand
// Comprehensive Fallback Handler class FallbackHandler { constructor(cacheManager, alternativeAPIs) { this.cache = cacheManager; this.alternatives = alternativeAPIs; } async executeWithFallbacks(primaryOperation, context) { const symbol = context.symbol; const dataType = context.dataType; try { // 1. Primary API attempt return await primaryOperation(); } catch (primaryError) { console.warn(`Primary API failed for ${symbol}:`, primaryError.message); try { // 2. Fresh cache fallback (< 2 hours old) const freshCache = await this.cache.get(symbol, dataType, { maxAge: 2 * 60 * 60 * 1000 }); if (freshCache) { return { ...freshCache, source: 'fresh_cache', warning: null }; } } catch (cacheError) { console.warn('Fresh cache failed:', cacheError.message); } try { // 3. Alternative API source const alternative = this.getAlternativeAPI(dataType); if (alternative) { const altData = await alternative.fetch(symbol); return { ...altData, source: 'alternative_api', warning: 'Using alternative data source' }; } } catch (altError) { console.warn('Alternative API failed:', altError.message); } try { // 4. Stale cache fallback (any age) const staleCache = await this.cache.get(symbol, dataType, { allowStale: true }); if (staleCache) { const age = Date.now() - staleCache.timestamp; return { ...staleCache, source: 'stale_cache', warning: `Data is ${Math.round(age / (60*60*1000))} hours old` }; } } catch (staleCacheError) { console.warn('Stale cache failed:', staleCacheError.message); } // 5. Graceful degradation with estimated values return this.generateEstimatedData(symbol, dataType, primaryError); } } generateEstimatedData(symbol, dataType, originalError) { // Return industry averages or basic estimates with clear warnings return { symbol, dataType, source: 'estimated', warning: 'Estimated data - all sources unavailable', error: originalError.message, data: this.getIndustryAverages(symbol, dataType), reliability: 'low' }; } }

📊 Health Monitoring & Metrics

Comprehensive health monitoring tracks system resilience, providing real-time visibility into error patterns, recovery effectiveness, and overall system stability.

📈 Key Resilience Metrics

99%

Uptime Target

Enterprise reliability

<2s

Failover Time

Average fallback activation

95%

Recovery Rate

Automatic recovery success

6

Protected APIs

Circuit breaker coverage

🎧 Monitoring Dashboard

🔥 Circuit Breaker Status

  • Real-time State: OPEN/CLOSED/HALF-OPEN per API
  • Failure Count: Current failure streak tracking
  • Recovery Timer: Time until next recovery attempt
  • Success Rate: Last 24 hours success percentage

🔄 Retry Analytics

  • Retry Rate: Percentage of requests requiring retries
  • Backoff Effectiveness: Average recovery time per attempt
  • Error Classification: Breakdown of retryable vs non-retryable
  • Jitter Impact: Thundering herd prevention effectiveness

🎯 Fallback Performance

  • Cache Hit Rate: Fresh vs stale cache utilization
  • Alternative Success: Backup API effectiveness
  • Degradation Rate: Frequency of estimated data usage
  • Recovery Speed: Time to restore primary service

💚 System Health

  • Overall Uptime: Cross-system availability percentage
  • Mean Time to Recovery: Average service restoration time
  • Error Rate Trends: Failure pattern analysis over time
  • Capacity Utilization: Resource usage during peak load

🔧 Automatic Recovery System

Self-healing architecture automatically detects and resolves system issues, minimizing manual intervention and ensuring continuous service availability.

🤖 Self-Healing Capabilities

🔍 Proactive Detection

  • Health Checks: Continuous API endpoint monitoring
  • Pattern Recognition: Early failure pattern detection
  • Threshold Monitoring: Response time and error rate tracking
  • Predictive Analysis: Machine learning-based failure prediction

⚡ Automatic Actions

  • Circuit Breaker Activation: Immediate failure isolation
  • Load Balancing: Traffic redirection to healthy services
  • Cache Extension: Automatic TTL extension during outages
  • Recovery Testing: Scheduled health verification
▶ // Show code example click to expand
// Automatic Recovery System class AutoRecoverySystem { constructor(errorManager) { this.errorManager = errorManager; this.recoveryActions = new Map(); this.healthChecks = new Map(); this.recoveryScheduler = new RecoveryScheduler(); } async initializeRecovery() { // Register recovery actions for each API this.recoveryActions.set('alpha-vantage', { healthCheck: () => this.pingAlphaVantage(), recovery: () => this.recoverAlphaVantage(), fallback: () => this.activateAlphaVantageFallback() }); // Start continuous health monitoring setInterval(() => this.performHealthChecks(), 30000); // Every 30 seconds // Schedule recovery attempts for failed services setInterval(() => this.attemptRecoveries(), 60000); // Every minute } async performHealthChecks() { for (const [service, actions] of this.recoveryActions) { try { const isHealthy = await actions.healthCheck(); this.updateServiceHealth(service, isHealthy); if (!isHealthy && !this.isInRecovery(service)) { await this.initiateRecovery(service); } } catch (error) { console.error(`Health check failed for ${service}:`, error); this.markServiceUnhealthy(service, error); } } } async initiateRecovery(service) { console.log(`🔧 Initiating recovery for ${service}`); const actions = this.recoveryActions.get(service); if (!actions) return; // Activate fallback immediately await actions.fallback(); // Schedule recovery attempts this.recoveryScheduler.schedule(service, async () => { try { await actions.recovery(); // Verify recovery const isHealthy = await actions.healthCheck(); if (isHealthy) { console.log(`✅ Recovery successful for ${service}`); this.markServiceHealthy(service); return true; // Recovery successful } return false; // Recovery failed, will retry } catch (error) { console.warn(`Recovery attempt failed for ${service}:`, error); return false; } }); } async pingAlphaVantage() { // Simple health check - minimal API call try { const response = await fetch('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=AAPL&interval=1min&apikey=demo', { timeout: 5000 }); return response.ok; } catch (error) { return false; } } }

🛡️ Enterprise Resilience Achieved

The Error Handling & Resilience System delivers 99% uptime through sophisticated circuit breakers, intelligent retry strategies, and comprehensive fallback mechanisms.

Self-healing architecture with automatic recovery - enterprise-grade reliability for mission-critical ESG intelligence!

← Back to Help Center 🛡️ Try Error Handling