← Back to all products

RPC Load Balancer

$10

RPC endpoint balancer with failover, rate limiting, and latency-based routing.

📁 21 files
TOMLPythonTypeScriptMarkdownJSON

📁 File Structure 21 files

rpc-load-balancer/ ├── LICENSE ├── README.md ├── config/ │ └── default.json ├── examples/ │ ├── basic.ts │ ├── monitoring.ts │ └── python-example.py ├── package.json ├── python/ │ ├── pyproject.toml │ └── rpc_balancer/ │ ├── __init__.py │ └── balancer.py ├── security-notes.md ├── src/ │ ├── CircuitBreaker.ts │ ├── HealthMonitor.ts │ ├── LoadBalancer.ts │ ├── RateLimiter.ts │ ├── index.ts │ ├── strategies/ │ │ ├── LeastLatency.ts │ │ ├── RoundRobin.ts │ │ └── WeightedRandom.ts │ └── types.ts └── tsconfig.json

📖 Documentation Preview README excerpt

RPC Load Balancer

Multi-provider RPC management with automatic failover, rate limiting, latency-based routing, and health monitoring.

Product 10 of the [defi-router](../../) store. Part of the CryptoForge DeFi toolkit.

Price: $9.99 | License: MIT | Runtime: Node.js >=18 | Language: TypeScript + Python


Overview

@cryptoforge/rpc-load-balancer distributes Ethereum JSON-RPC requests across multiple providers (Alchemy, Infura, QuickNode, Ankr, public RPCs) based on latency, error rates, and rate limits. It handles failover automatically so your application stays online even when individual providers go down.

Key Features

  • 3 load balancing strategies — Round-robin, least-latency (EMA), weighted-random
  • Automatic failover — If a provider errors, the request retries on the next best provider
  • Circuit breaker — Opens after N consecutive failures, half-open probes after cooldown
  • Per-provider rate limiting — Token bucket algorithm respects each provider's RPS limit
  • Health monitoring — Latency P50/P95/P99, error rate, uptime, requests/minute per provider
  • Batch support — JSON-RPC batch protocol for multi-call efficiency
  • Convenience methodseth_call, eth_getBalance, eth_blockNumber, and more
  • Python wrapper — Async implementation with the same strategy support
  • Zero ethers dependency — Pure HTTP transport; ethers is an optional peer dependency

Architecture


┌──────────────────────────────────────────────────────────────────────┐
│                          LoadBalancer                                │
│                                                                      │
│  ┌──────────────────┐  ┌──────────────────┐  ┌───────────────────┐  │
│  │  Strategy Engine   │  │  Health Monitor   │  │  Circuit Breaker  │  │
│  │  • Round-robin     │  │  • Latency EMA    │  │  • Closed         │  │
│  │  • Least-latency   │  │  • P50/P95/P99    │  │  • Open           │  │
│  │  • Weighted-random │  │  • Error rate      │  │  • Half-open      │  │
│  └──────────────────┘  │  • Uptime           │  │  • Probe count    │  │
│                         │  • RPM              │  └───────────────────┘  │
│                         └──────────────────┘                           │
│                                                                        │
│  ┌──────────────────────────────────────────────────────────────────┐  │
│  │                     Per-Provider State                            │  │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────┐ │  │
│  │  │ Alchemy   │ │ Infura   │ │QuickNode │ │ Ankr     │ │Public │ │  │
│  │  │ RPS: 25   │ │ RPS: 10  │ │ RPS: 25  │ │ RPS: 30  │ │RPS: 5│ │  │
│  │  │ W: 5      │ │ W: 4     │ │ W: 5     │ │ W: 3     │ │W: 1  │ │  │
│  │  └──────────┘ └──────────┘ └──────────┘ └──────────┘ └───────┘ │  │
│  └──────────────────────────────────────────────────────────────────┘  │
│                                                                        │
│  ┌──────────────────────────────────────────────────────────────────┐  │
│  │  Token Bucket Rate Limiter (per provider)                        │  │
│  │  Continuous refill · Capacity = maxRPS · Non-blocking tryAcquire │  │
│  └──────────────────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────────────┘

Request Flow:
  request() → Strategy selects provider → Rate limiter check → Circuit breaker check
           → HTTP POST (undici) → Record latency/error → Return result or failover

... continues with setup instructions, usage examples, and more.

📄 Code Sample .py preview

examples/python-example.py """ Python RPC Load Balancer usage example. Demonstrates async usage with multiple providers, strategy selection, and health monitoring. """ import asyncio from rpc_balancer import RPCLoadBalancer, Strategy, RPCError async def main() -> None: providers = [ { "name": "Alchemy", "url": "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY", "weight": 5, "max_rps": 25, "priority": 0, }, { "name": "Infura", "url": "https://mainnet.infura.io/v3/YOUR_KEY", "weight": 4, "max_rps": 10, "priority": 1, }, { "name": "Public", "url": "https://eth.llamarpc.com", "weight": 1, "max_rps": 5, "priority": 10, }, ] async with RPCLoadBalancer( providers, strategy=Strategy.LEAST_LATENCY, timeout_s=8.0, max_retries=3, ) as balancer: # --- Basic requests --- try: block = await balancer.eth_block_number() print(f"Current block: {int(block, 16)}") balance = await balancer.eth_get_balance( "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" ) # ... 32 more lines ...
Buy Now — $10 Back to Products