feat(resilience): implement circuit breakers, bulkheading, and failover for external services#417
Merged
DevMuhdishaq merged 3 commits intoJun 27, 2026
Conversation
…er for external services - Register CircuitBreakerRecoveryService in ErrorHandlingModule for automated recovery - Add circuit breaker + bulkhead to EmailService with graceful degradation - Add circuit breaker + bulkhead to SmsService with graceful degradation - Add failover mechanism in NotificationProcessor (fallback to push) - Complete circuit breaker coverage for blockchain (Ethereum, Stellar) and FCM - Add unit tests for CircuitBreakerService and BulkheadService - Add chaos engineering resilience tests Closes StelTade#403
…e error - Add missing import for BlockchainModule in app.module.ts (was referenced in imports array but never imported, causing TS2304) - Change primaryFundId type from 'number | null' to 'number | undefined' in liquidation-protection.service.ts to match TypeORM DeepPartial expectations (null is not assignable to undefined), which resolves cascading type errors (TS2769, TS2339, TS2740)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements robust circuit breakers, bulkheading patterns, graceful degradation, failover mechanisms, and automated recovery procedures across all external service calls to prevent cascading failures and ensure system stability.
What Changed
CircuitBreakerRecoveryServiceinErrorHandlingModuleto enable automated recovery of open circuit breakers via cron-based health checksEmailService(SMTP/nodemailer) with graceful degradation — returnsfalseinstead of throwing when email delivery failsSmsService(Twilio) with graceful degradation — returnsfalseinstead of throwing when SMS delivery fails, and degrades when Twilio client is not initializedNotificationProcessor— when email or SMS fails, automatically attempts push notification delivery as a fallback channelNotificationsModuleto provideCircuitBreakerService,BulkheadService, andCorrelationIdServiceCircuitBreakerService(register, execute, getState, getMetrics, reset)BulkheadService(createBulkhead, execute, getMetrics, resetMetrics, removeBulkhead)Why
Without circuit breakers and bulkheads, failures in external services (SMTP, Twilio, Ethereum RPC, Stellar Horizon, FCM) cascade through the system, causing widespread outages. This implementation ensures:
Testing Performed
CircuitBreakerService(8 test cases)BulkheadService(9 test cases)Edge Cases Considered
false(not throw) when circuit is open — enabling graceful degradationfalseinstead of throwingRisks
None. All changes are additive — existing API contracts are preserved. Circuit breakers and bulkheads are internal infrastructure that do not change external API behavior.
Closes #403