Overview
Sol RPC Router implements Redis-backed rate limiting to control request throughput per API key. Rate limits are enforced before requests reach backend nodes, protecting your infrastructure from abuse.Redis Configuration
Rate limiting requires a Redis instance. Configure the connection in yourconfig.toml:
Redis connection URL for rate limiting state storage.Format:
redis://[host]:[port]/[database]Examples:redis://127.0.0.1:6379/0- Local Redis, database 0redis://localhost:6379- Local Redis, default databaseredis://redis.example.com:6379/1- Remote Redis, database 1
How Rate Limiting Works
- API Key Extraction: Each request must include an API key (typically via header or query parameter)
- Redis Lookup: Router checks current request count for the API key in Redis
- Limit Enforcement: If limit exceeded, request is rejected with HTTP 429
- Request Forwarding: If within limits, request is forwarded to backend
- Counter Update: Redis counter is incremented with TTL for sliding window
API Key Authentication
Requests must include an API key for rate limiting to work. Common patterns:Query Parameter (Required)
Sol RPC Router uses the
api-key query parameter (with hyphen) for authentication. The API key is automatically stripped from the request before forwarding to backends for security.Configuring Rate Limits
Rate limits are configured per API key using therpc-admin CLI tool. Each API key has a rate_limit value (in requests per second) stored in Redis.
Redis Key Structure
Sol RPC Router uses two types of Redis keys: API Key Metadata:Setting Limits via rpc-admin
Use therpc-admin CLI to create and update rate limits:
Manual Redis Configuration (Advanced)
You can also set limits directly in Redis:Rate Limit Response
When a rate limit is exceeded, the router returns: HTTP Status:429 Too Many Requests
Response Body:
Exact response format may vary based on your implementation. Check your middleware configuration.
Monitoring Rate Limits
Rate limiting metrics are exposed via Prometheus:Common Patterns
Development Environment
debug_config.toml:1-7).
Production Environment
High Availability Redis
For Redis Cluster or Sentinel setups, ensure your connection string matches your Redis configuration. The router uses the standard Redis client which supports various deployment modes.
Redis Connection Requirements
Redis must be running and accessible before starting the router
Redis URL must be non-empty (validated at startup)
Network connectivity to Redis host required
Appropriate Redis permissions for GET/SET/EXPIRE operations
Connection Failures
If Redis is unavailable:- Startup: Router may exit if Redis connection is critical
- Runtime: Requests may be rejected or allowed through (depending on fail-open/fail-closed configuration)
- Metrics:
redis_connection_errors_totalcounter incremented
Best Practices
Use Redis persistence
Enable AOF or RDB snapshots to prevent losing rate limit state during Redis restarts.
Set appropriate TTLs
Configure Redis key expiration to automatically clean up old counters and prevent unbounded memory growth.
Monitor Redis performance
Track Redis latency and memory usage. Slow Redis operations will impact request latency.
Use dedicated Redis database
Separate rate limiting state from other application data using different database numbers (e.g.,
/0, /1).Plan for Redis failures
Decide whether to fail-open (allow requests) or fail-closed (reject requests) when Redis is unavailable.
Secure Redis access
Use Redis AUTH, TLS encryption, and network isolation in production environments.
Troubleshooting
All Requests Return 429
Symptoms: All requests rate limited regardless of API key Solutions:- Check Redis counter values:
redis-cli KEYS 'ratelimit:*' - Verify correct API key extraction
- Check if limits are set too low
- Clear Redis counters:
redis-cli FLUSHDB(development only)
Rate Limiting Not Working
Symptoms: No rate limits enforced, all requests pass through Solutions:- Verify
redis_urlis configured correctly - Check Redis connectivity:
redis-cli -u redis://127.0.0.1:6379/0 PING - Ensure API keys are being sent with requests
- Check metrics for
redis_connection_errors_total
Redis Connection Errors
Symptoms: Logs show Redis connection failures Solutions:- Verify Redis is running:
redis-cli PING - Check network connectivity to Redis host
- Verify
redis_urlformat and credentials - Check firewall rules and security groups
Configuration Example
Complete example with Redis rate limiting:config.example.toml:1-25.