core: implement Horizon failover with multiple RPC endpoints#86
Open
Godfrey-Delight wants to merge 7 commits into
Open
core: implement Horizon failover with multiple RPC endpoints#86Godfrey-Delight wants to merge 7 commits into
Godfrey-Delight wants to merge 7 commits into
Conversation
Created src/stellar/horizon-client.service.ts with multi-endpoint support (configurable via STELLAR_HORIZON_URLS env var, comma-separated), a circuit breaker per endpoint (3 failures -> 30s cooldown -> half-open probe -> automatic recovery), and auto-failover to the next healthy endpoint on transient failures (timeouts, 5xx, rate limits, network errors). Created src/stellar/stellar.service.ts as a thin public-facing wrapper. Updated src/modules/health/health.service.ts to consume the horizon client and report per-endpoint circuit breaker statuses (closed/open/half-open, failure count, last error, primary indicator) in the GET /health response. Two new config keys are supported: STELLAR_HORIZON_URLS (comma-separated list) with fallback to the existing STELLAR_HORIZON_URL. Closed StepFi-app#27
EmeditWeb
reviewed
Jul 21, 2026
EmeditWeb
left a comment
Member
There was a problem hiding this comment.
Review verdict: ✅ APPROVE
Clean multi-RPC failover. withFailover<T> rotates through all configured endpoints, tries each on failure, and throws only once every endpoint is exhausted; endpoints come from env with a sensible testnet default. No any; 21 tests pass locally; CI green.
One note: submitTransaction also goes through withFailover, so if the first endpoint accepts the transaction but its response is lost, a retry could re-submit to a second endpoint. For Stellar this is largely idempotent (the same signed tx / sequence number yields the same result or tx_bad_seq), so it's low-risk — but a short code comment noting that submit-retries rely on ledger-level idempotency would be worth adding. Otherwise merge-ready.
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.
🔗 Related Issue
Closes #27
🔖 Title
Created src/stellar/horizon-client.service.ts with multi-endpoint support (configurable via STELLAR_HORIZON_URLS env var, comma-separated), a circuit breaker per endpoint (3 failures -> 30s cooldown -> half-open probe -> automatic recovery), and auto-failover to the next healthy endpoint on transient failures (timeouts, 5xx, rate limits, network errors). Created src/stellar/stellar.service.ts as a thin public-facing wrapper. Updated src/modules/health/health.service.ts to consume the horizon client and report per-endpoint circuit breaker statuses (closed/open/half-open, failure count, last error, primary indicator) in the GET /health response. Two new config keys are supported: STELLAR_HORIZON_URLS (comma-separated list) with fallback to the existing STELLAR_HORIZON_URL.
📝 Description
Replaces the single hardcoded Horizon endpoint with a multi-endpoint client that fails over automatically when the primary goes down, so the API doesn't stop working on a single endpoint outage. Adds a circuit breaker per endpoint to stop hammering a failing one, and surfaces per-endpoint health status through the existing /health route for monitoring.
🔄 Changes Made
-Added src/stellar/stellar.service.ts as a thin wrapper exposing the horizon client to the rest of the app
📸 Screenshots (if applicable)
🗒️ Additional Notes