Prerequisites
Before deploying the Sol RPC Router, ensure you have:- Rust 2021 edition (stable toolchain)
- Redis instance for API key storage and rate limiting
- Prometheus (optional) for metrics collection
- Grafana (optional) for dashboard visualization
Building the Application
Production Build
Compile the router with optimizations:target/release/sol-rpc-router- Main RPC proxy servertarget/release/rpc-admin- CLI tool for API key management
Configuration
Environment Setup
Create a production configuration file (config.toml):
Configuration Validation
The router validates configuration on startup:redis_urlmust be non-empty- At least one backend required
- Backend labels must be unique and non-empty
- Backend weights must be > 0
proxy.timeout_secsmust be > 0method_routesvalues must reference existing backend labels
Starting the Router
Basic Startup
Startup Logs
On successful startup, you’ll see:Server Architecture
The router starts three concurrent servers:1. HTTP Server (Port 28899)
Handles JSON-RPC requests:POST /- Main RPC proxy endpointPOST /*path- Proxy with subpath supportGET /health- Health check endpointGET /(WebSocket upgrade) - WebSocket connections on main port
2. WebSocket Server (Port 28900)
Dedicated WebSocket port following Solana convention (HTTP port + 1):ws://host:28900/- WebSocket subscriptions
3. Metrics Server (Port 28901)
Prometheus metrics endpoint:GET /metrics- Prometheus-formatted metrics
Production Considerations
Redis Connection
The router fails immediately if Redis is unavailable:Health Checks
A background task continuously monitors backend health:- Runs every
interval_secs(default: 30s) - Calls configured RPC method (default:
getSlot) - Tracks consecutive failures/successes
- Updates backend health status atomically
- Marks backends unhealthy after threshold failures
- Excludes unhealthy backends from load balancing
Slot Lag Detection
The health checker compares backend slots:- Determines consensus tip (max slot across all backends)
- Marks backends as unhealthy if they lag by more than
max_slot_lagslots - Logs warnings when lag is detected
Port Availability
The router requires three consecutive ports:- HTTP port (configurable, default: 28899)
- WebSocket port (HTTP port + 1, default: 28900)
- Metrics port (configurable, default: 28901)
Creating API Keys
Before accepting requests, create at least one API key:Process Management
Systemd Service
Create/etc/systemd/system/sol-rpc-router.service:
Docker Deployment
Create aDockerfile:
Security
Network Security
- HTTP/WS ports (28899, 28900): Expose to clients
- Metrics port (28901): Restrict to monitoring systems only
- Redis: Keep on private network, never expose publicly
API Key Security
API keys are stored in Redis:- Use strong, randomly generated keys
- Rotate keys regularly
- Revoke compromised keys immediately with
rpc-admin revoke
Rate Limiting
Each API key has a per-second rate limit enforced atomically in Redis:- Prevents abuse
- Protects backend infrastructure
- Returns
429 Too Many Requestswhen exceeded
Logging
The router usestracing for structured logging. Log levels:
INFO: Normal operations (requests, health checks, config reloads)WARN: Non-critical issues (health check failures, rate limits)ERROR: Critical errors (Redis failures, invalid config)
Setting Log Level
Use theRUST_LOG environment variable:
Next Steps
- Monitor your deployment with Prometheus and Grafana
- Configure hot reload for zero-downtime updates
- Troubleshoot common issues