How to Use getHealth
Learn getHealth use cases, code examples, request parameters, response structure, and tips.
The getHealth
endpoint is used to check the current health status of a Solana RPC node. A healthy node is generally considered to be one that is operational and reasonably synchronized with the rest of the cluster (specifically, within a certain slot distance of the latest cluster confirmed slot, known as HEALTH_CHECK_SLOT_DISTANCE
).
This endpoint is crucial for monitoring node health, especially for applications or infrastructure that rely on the availability and reliability of an RPC node.
How it Works
The getHealth
method uses the standard JSON-RPC POST mechanism with the method getHealth
. This method checks if the RPC node is healthy and synchronized with the Solana cluster.
Common Use Cases
- Node Monitoring: Regularly check the health of RPC nodes to ensure they are operational and synchronized.
- Load Balancing: Use health checks to determine if a node should receive traffic in a load-balanced setup.
- Failover Systems: Trigger failover to a backup node if a primary node becomes unhealthy.
- Debugging Connectivity: Quickly ascertain if an RPC node is responsive.
Request Parameters
This method does not take any parameters.
Response Structure
- For JSON-RPC
getHealth
POST:result
:"ok"
if the node is healthy.- It might return an error object or other string values (like
"behind"
or"unknown"
) if unhealthy, though the exact error response for an unhealthy node can be unstable or vary between providers.
Examples
1. Check Node Health using JSON-RPC (POST with cURL)
Expected JSON-RPC response (for a healthy node):
Developer Tips
- Definition of Healthy: “Healthy” generally means the node is responsive and not too far behind the cluster’s tip. The exact slot difference (
HEALTH_CHECK_SLOT_DISTANCE
) can be configured on the node. - Interpreting
"behind"
or"unknown"
: If you receive"behind {distance}"
or"unknown"
, the node is operational but may not be fully caught up or able to ascertain its status relative to the cluster. Depending on your application’s requirements, you might treat these states differently. - Provider Differences: The exact behavior and response codes/bodies for an unhealthy node might vary slightly between RPC providers.
- Error Handling: Always implement proper error handling when calling
getHealth
, as network issues or node problems can cause the request to fail entirely.
This guide provides the necessary information to use the getHealth
endpoint for monitoring the status of a Solana RPC node.