Subscription Types Overview
Polling
Best for: Most applications
- Batched account fetches
- Predictable RPC usage
- Good performance
WebSocket
Best for: Real-time updates
- Lower latency
- Event-driven
- Higher RPC load
gRPC
Best for: High frequency
- Lowest latency
- Highest throughput
- Requires infrastructure
Polling Subscription
Polling is the recommended approach for most applications. It usesBulkAccountLoader to batch account fetches efficiently.
Setup
Configuration
BulkAccountLoader
required
Shared BulkAccountLoader instance for batching
number
Milliseconds between polls (default: 1000)
Advantages
- Efficient: Batches multiple account fetches into single RPC calls
- Predictable: Constant RPC load
- Reliable: No WebSocket connection issues
- Shared: One loader can serve multiple accounts
Example: Multiple Users
WebSocket Subscription
WebSocket provides real-time updates via Solana’s account change notifications.Setup
Resubscription Options
boolean
Automatically reconnect on disconnect (recommended: true)
number
Timeout before resubscription attempt (default: 30000)
boolean
Log errors during resubscription attempts
Handling Events
Advantages
- Low latency: Immediate updates on account changes
- Event-driven: React to changes as they happen
- Real-time: Best for market making and high-frequency strategies
Considerations
gRPC Subscription
gRPC provides the lowest latency and highest throughput using Yellowstone or Laser gRPC infrastructure.Prerequisites
- Access to a Yellowstone or Laser gRPC endpoint
- Authentication token
Setup with Yellowstone
Setup with Laser (Helius)
Configuration
string
required
gRPC server endpoint URL
string
Authentication token
object
gRPC channel configuration options
Advantages
- Lowest latency: Sub-millisecond updates
- High throughput: Handle many accounts efficiently
- Reliable: Dedicated infrastructure
- Professional: Used by market makers
Considerations
gRPC requires additional infrastructure and typically costs more than standard RPC. Best for professional trading operations.
Listening to Updates
All subscription types emit events that you can listen to:User Account Updates
Market Updates
Oracle Price Updates
Subscription Lifecycle
Subscribing
Unsubscribing
Fetching Latest Data
Best Practices
Choose the right subscription type
Choose the right subscription type
- Polling: Default choice for most applications
- WebSocket: When you need real-time updates and can handle reconnections
- gRPC: For professional market making and HFT
Handle errors gracefully
Handle errors gracefully
Monitor subscription health
Monitor subscription health
Performance Comparison
Next Steps
Account Subscribers API
Detailed API documentation
Oracle Integration
Work with oracle price feeds
WebSocket API
WebSocket subscriber reference
gRPC API
gRPC subscriber reference