Overview
Some cloud providers and load balancers (like Cloudflare, Fly.io) automatically close gRPC connections if the client doesn’t send any data for a period of time. The ping/pong mechanism keeps your connection alive by periodically exchanging heartbeat messages.How It Works
Yellowstone gRPC implements a bidirectional ping/pong mechanism:- Server sends Ping - The gRPC server sends a
Pingmessage to the client every 15 seconds - Client responds with Pong - The client should respond by sending a
SubscribeRequestwith apingfield - Server sends Pong - The server acknowledges with a
Pongmessage containing the ping ID
Basic Implementation
- Rust
- TypeScript
The Rust example shows the complete bidirectional ping/pong implementation:
Complete Working Example
Here’s the complete Rust example from the Yellowstone gRPC repository:- Initial subscription setup
- Periodic client-initiated pings (every 3 seconds)
- Handling server pings
- Handling server pongs
- Processing other updates (slots in this case)
Client-Initiated Pings
While the server sends pings every 15 seconds, you can also send pings from the client at any interval:- More frequent heartbeats if needed
- Can detect connection issues faster
- Useful for aggressive load balancers
Ping ID Tracking
Theid field in pings and pongs lets you track round-trip time:
When to Use Ping/Pong
Required
Cloud Providers
- Cloudflare
- Fly.io
- Some AWS configurations
- Load balancers with idle timeouts
Optional
Direct Connections
- Direct validator connections
- Internal networks
- Short-lived connections
- Testing environments
Recommended
Production Systems
- Long-lived subscriptions
- Critical monitoring
- Always-on services
- Connection health checks
Not Needed
Short Operations
- One-time queries
- Quick tests
- Development without proxies
Handling Connection Issues
Use ping/pong to detect and handle connection problems:Ping/Pong with Deshred Subscriptions
The ping/pong mechanism also works with deshred subscriptions:Best Practices
- Always implement ping/pong for production systems
- Respond quickly to server pings - don’t block the event loop
- Set reasonable intervals - 3-15 seconds is typical
- Track connection health - monitor pong responses
- Implement reconnection logic - handle connection failures gracefully
- Don’t ping too frequently - respect server resources
Troubleshooting
Connection keeps closing
Connection keeps closing
- Make sure you’re responding to server pings with pongs
- Check your load balancer/proxy timeout settings
- Implement client-initiated pings every 5-10 seconds
- Verify your ping response code is correct
Not receiving server pings
Not receiving server pings
- Server pings are sent every 15 seconds - wait at least 20 seconds
- Check that your stream is actively reading messages
- Verify your connection is established properly
- Look for ping messages in debug output
Pongs not coming back
Pongs not coming back
- Verify you’re sending pings with the correct format
- Check that the ping ID is a valid i32
- Ensure the subscription channel is still open
- Look for errors in the stream
High latency on pongs
High latency on pongs
- This may indicate network issues
- Check your network connection quality
- Monitor round-trip times over time
- Consider using a closer gRPC endpoint
Server Ping Interval
The Yellowstone gRPC server sends ping messages every 15 seconds by default. This is mentioned in the README:
“Since we sent a Ping message every 15s from the server, you can send a subscribe request with ping as a reply and receive a Pong message.”
Next Steps
- Learn about Subscribing to set up your initial subscription
- Implement Filtering to narrow down updates
- Understand Commitment Levels for your use case