WebSocket Overview
The router proxies WebSocket connections to backend Solana RPC nodes, enabling subscription methods likeaccountSubscribe, logsSubscribe, and slotSubscribe. WebSocket connections use the same authentication, rate limiting, and weighted load balancing as HTTP requests.
Connection Methods
Clients can connect via two equivalent endpoints:- Main HTTP Port:
GET /withUpgrade: websocketheader - Dedicated WebSocket Port: HTTP port + 1 (e.g., if HTTP is 28899, WebSocket is 28900)
GET / (WebSocket Upgrade)
Upgrade an HTTP connection to WebSocket and proxy to a backend Solana RPC node.Connection URL
Authentication
WebSocket connections require an API key passed as a query parameter:401 Unauthorized: Invalid or missing API key429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Redis connection error503 Service Unavailable: No healthy WebSocket backends available
Backend Selection
The router selects backends with WebSocket support (ws_url configured) using weighted random selection among healthy backends. Backends without ws_url are excluded from WebSocket routing.
Configuration:
Connection Lifecycle
Message Forwarding
All WebSocket frames are relayed transparently between client and backend:- Text: JSON-RPC subscription requests/responses/notifications
- Binary: Raw binary data (if used by backend)
- Ping/Pong: Keepalive frames (forwarded bidirectionally)
- Close: Graceful shutdown signal
Supported Subscription Methods
The router transparently proxies all Solana WebSocket subscription methods:Subscribe to account data changes
Subscribe to transaction logs
Subscribe to program account changes
Subscribe to transaction confirmation
Subscribe to slot changes
Subscribe to slot update notifications
Subscribe to root changes
Subscribe to vote transactions
Connection Examples
Error Responses
Returned before upgrade when:
- No
api-keyquery parameter provided - Invalid API key
- API key is inactive
"Unauthorized"Returned when the API key exceeds its rate limit during connection attempt.Response body:
"Rate limit exceeded"Returned when Redis connection fails during key validation.Response body:
"Internal Server Error"Returned when no healthy backends with
ws_url configured are available.Response body: "No healthy WebSocket backends available"Rate Limiting
WebSocket connections are rate limited at connection time using the same Redis-backed mechanism as HTTP requests:- API key is validated and rate limit checked before the upgrade
- If rate limit is exceeded, connection is rejected with
429 Too Many Requests - After successful upgrade, messages are not individually rate limited
- Long-lived connections do not count against the per-second rate limit
Metrics
WebSocket connections emit the following metrics (see Metrics Endpoint for details):ws_connections_total: Counter of connection attempts by statusws_active_connections: Gauge of currently open connectionsws_messages_total: Counter of messages relayed (client→backend, backend→client)ws_connection_duration_seconds: Histogram of connection lifetimes
backend and owner labels for granular analysis.
Monitoring Active Connections
Query Active Connections
Connection Timeout
WebSocket connections do not have an idle timeout. Connections remain open until:- Client sends a Close frame
- Backend sends a Close frame
- Network error or connection loss
- Router shutdown
Best Practices
- Reconnection Logic: Implement automatic reconnection with exponential backoff
- Heartbeat: Use Ping/Pong frames to detect stale connections
- Error Handling: Handle backend disconnects and router restarts gracefully
- Subscription Management: Track subscription IDs and resubscribe on reconnect
- Rate Limit Headroom: Ensure API key rate limits account for subscription setup traffic
Example: Reconnection with Backoff
Reconnection Logic