DNM: BCN - Multi provider reference #4080
Open
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.
Intended as a technical reference for multi-provider infrastructure implementation. Code changes annotate relevant functions and design patterns.
Below is a copy of file: packages/bitcore-node/MultiProviderReference.Md. File added for easier commenting
Table of Contents
Architecture Overview
Context: Moving to Provider-Based Infrastructure
The Challenge: Currently managing 118.4 TB of blockchain data across local nodes with significant storage costs (~$100K/year). Moving to external providers for all EVM chains (ETH, Polygon, BASE, ARB, OP) eliminates storage while maintaining service reliability.
Key Decision: Use multiple providers with automatic failover instead of depending on a single provider. This prevents vendor lock-in and ensures high availability.
RPC vs Indexed APIs: Two Different Patterns
getWeb3()This migration focuses on Indexed APIs - implementing the same multi-provider pattern that RPC already uses.
The Multi-Provider Pattern
Sequential vs Parallel Strategy
Why Sequential Failover:
Multi-Provider Benefits
Example Provider Selection
Rollout Strategy
Phased approach to minimize risk:
File Structure
IIndexedAPIAdapter Interface and Adapters
Multi-Provider CSP Module Structure
API Adapter Interface
Why Adapters?
Each provider returns blockchain data in different formats (different field names, hex vs decimal, pagination styles). Without adapters, provider-specific logic spreads throughout the codebase creating tight coupling and making it difficult to add/remove providers. Adapters provide:
Core Interface Definition
Provider Adapters
Moralis Adapter
Chainstack Adapter
Adapter Factory
Multi-Provider Module
Why Multi-Provider?
Depending on a single external provider creates a single point of failure - if that provider has an outage, rate limits, or pricing changes, our entire service is impacted. A multi-provider architecture ensures:
MultiProviderEVMStateProvider
Circuit Breaker
Why Circuit Breaker?
Without circuit breakers, the system continues trying failing providers on every request, wasting time and degrading performance. Circuit breakers automatically detect and bypass unhealthy providers, then periodically test for recovery:
Implementation
State Transitions
Stream Improvements
Why Stream-Based Architecture?
Large result sets (like address transaction history) can't be loaded entirely into memory. Streams process data in chunks, providing memory efficiency and better performance. Moving to pure stream returns (instead of passing req/res objects) also decouples business logic from HTTP layer:
Architectural Change: Stream-Based Data Flow
Old Pattern (Coupled):
New Pattern (Decoupled):
Benefits:
Stream Transform Utilities
Metrics
Why Metrics?
With multiple providers, you need visibility into which providers are performing well, which are failing, and where costs are accumulating. Metrics enable:
Provider Metrics Collection
Metrics Integration in MultiProviderCSP
Configuration
Config Interface
Example Configuration
Implementation Checklist
Core Components
IIndexedAPIAdapterinterfaceAdapterFactoryMoralisAdapterimplementationChainstackAdapterimplementationTatumAdapterimplementationCircuitBreakerwith improved state namesMultiProviderEVMStateProviderExternalApiStreamenhancementsProviderMetricscollectionTesting
Monitoring
Future Considerations
After Testing & Validation
Once multi-provider architecture is validated on BASE and ETH testnets, consider:
Local Node Retention Policy (if keeping local nodes as fallback)
Additional Providers
Advanced Features