RPC endpoint health check: freshness, not liveness

By John Sullivan · November 29, 2026 · 9 min read · #rpc endpoint #health check #node freshness #failover #json-rpc

Your failover rule has a health check in it, and the check passes on a node that is behind. A liveness check confirms something is listening and answering; the node that costs you a night is listening, fast and stale. An RPC endpoint health check that measures freshness is a different predicate, and you have to write it yourself.

Neither the JSON-RPC 2.0 specification nor the Ethereum execution-apis specification defines a health-check method, and neither attaches any freshness meaning to the methods it does define [1] [2]. The nearest thing either has is net_listening, and it is a liveness check, not a freshness one [3]. So the predicate is yours: what freshness means when you do not control the node, which signals measure it, and how to set a threshold you can defend.

Liveness is the wrong question

net_listening is defined as "Returns true if the client is actively listening for network connections" [3]. It says nothing about the chain. A node can be listening and be forty thousand blocks behind.

eth_blockNumber is defined as "Returns the number of most recent block" [4]. It carries no reference head, so it cannot tell you whether that number is current. The latest tag is "the most recent block in the canonical chain observed by the client", and the specification notes it "may be re-orged out of the canonical chain even under healthy/normal conditions" [5]. Observed by the client is the phrase that matters: the tag is relative to the node's own view, which is why it cannot detect that the view is stale.

eth_syncing looks like the answer and is not. The specification defines its return as "an object with data about the sync status or false" [6] and stops there. It does not say that false means the node is at the head. A node that is not syncing at all — freshly started, stalled, waiting on its consensus client — returns false too, as our write-up on eth_syncing notes [7].

A stalled node still answers, promptly, with a 200 and an old number [7]. Three ways a node diverges from the head while passing every liveness check: it is fully synced to a fork; its peer set is bad and its head is hours old; it is serving cached state from before a reorg.

A health-checking standard does exist for a comparable protocol — gRPC defines a Health service with Check and Watch [8] [8]. JSON-RPC defines none. That is why the predicate underneath your failover rule is implementation-defined, and why the rule behaves only as well as the predicate you give it. A transport's own health check has the same shape: the viem fallback transport ranks endpoints on its own terms, and the predicate you hand it is still yours to choose.

The three signals that measure freshness

Head lag. Ask the endpoint for eth_blockNumber and ask something else for the same number. The difference is the lag. The something else can be a second endpoint or a public source; what it cannot be is the endpoint under test, because a node reports the head it believes in and has no way to report that the belief is wrong [4] [5].

Block age. Take the timestamp of the endpoint's latest block and subtract it from wall-clock time. timestamp is a required member of the Block object, so one eth_getBlockByNumber call gives you both the height and the block's own time [5]. This catches the node that is internally consistent and externally stale — the case where a node reports a block far older than it should be while answering everything else correctly [9]. It is also the one signal that needs no second endpoint, which is why it is worth having even when you have one — see is your RPC node synced.

Agreement. Ask two endpoints for the same height and compare the block hashes. hash is a required member of the Block object [5], so the comparison uses documented fields only. This is the only one of the three that catches a node synced to a fork or to the wrong chain, because such a node is at the head of its own chain and internally consistent.

Each signal has a blind spot. Head lag misses a fork: a node on a fork can sit at the same height as the reference and still be wrong. Block age misses a fast-but-wrong node: a node on a fork produces blocks with recent timestamps. Agreement misses a node that is behind but agrees on the blocks it has — it matches the reference at every height it has reached, and the heights it has not reached are the ones you needed.

Three signals because no one of them is sufficient. We run a cross-upstream comparison in production: we compare each upstream's tag lag with the others serving the same chain and drop the outliers from rotation [9].

Setting a threshold you can defend

Start with the tolerance, not the number. How stale may a read be before it is wrong for what you are doing? That is a property of your application, and nobody outside it can answer. A balance you display and a balance you settle against have different tolerances.

Convert it into blocks:

threshold_in_blocks = time_tolerance / block_time

Both inputs are yours. time_tolerance is the answer above, in seconds. block_time is the interval your chain actually produces blocks at, which is not always the interval its documentation advertises.

A fixed block count is wrong on a chain whose block time changes, and a fixed second count breaks on a chain with sparse blocks [9]. The divergence is large: in a measurement of finalized-tag lag across the chains we serve on 2026-09-30, Arbitrum Nova's finalized block was 3,603 seconds behind but only 3 blocks behind, because Nova produces blocks when there is activity [9]. That is a measurement of one chain's finality lag on one day, not a threshold.

No threshold is documented — not in the JSON-RPC 2.0 specification, not in execution-apis, not in our docs [1] [2] [10] [11]. Your tolerance is the input and the threshold is the output. Check the block count and the elapsed time both, because a node can pass one and fail the other.

The check, and where it goes in the loop

Two documented methods and a plain HTTP POST are enough. The request shape is POST /rpc/{chain}?key={API_KEY} with Content-Type: application/json and a JSON-RPC 2.0 body [10]. The function returns a verdict instead of throwing, because the caller acts differently on each one.

// SCHEDULE: your own interval and backoff go here.
async function rpc(url: string, method: string, params: unknown[]) {
  const res = await fetch(url, {
    method: "POST", headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
  });
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  const { result, error } = await res.json();
  if (error) throw new Error(error.message);
  return result;
}

async function checkFreshness(endpoint: string, reference: string,
  maxLagBlocks: number, maxAgeSeconds: number): Promise<"fresh" | "stale" | "failed"> {
  try {
    const headHex = await rpc(endpoint, "eth_blockNumber", []);
    const refHex = await rpc(reference, "eth_blockNumber", []);  // never the endpoint being judged
    const lag = Number(BigInt(refHex)) - Number(BigInt(headHex));
    const block = await rpc(endpoint, "eth_getBlockByNumber", [headHex, false]);
    const age = Date.now() / 1000 - Number(BigInt(block.timestamp));  // block's own time
    return lag > maxLagBlocks || age > maxAgeSeconds ? "stale" : "fresh";
  } catch {
    return "failed";  // transport error, a different verdict from stale
  }
}

Three details carry the correctness:

  • The reference head must come from somewhere other than the endpoint being judged. If both numbers come from the same node, the lag is always zero and the check always passes.
  • Block age comes from the block's own timestamp, not from when the response arrived. A node that answers slowly with a current block is fresh; a node that answers instantly with an old block is not.
  • A failed check and a stale check are different verdicts. A timeout is a transport or availability problem; a lagging node is a data-correctness problem. They need different responses, and a check that throws collapses them into one.

Where the check sits depends on what you do with the answer. If a failed check means the read still has to happen, the read needs a second path — request hedging for JSON-RPC reads covers that. If a failed check means you retry, the retry needs a schedule, and 429 handling and backoff belong to that piece rather than this one. The check itself should carry no polling interval: the interval is a property of your traffic, not of the predicate.

What this does not tell you

A freshness check is a sample, not a prediction. It tells you the node was at the head when you asked. It says nothing about the next five minutes.

It cannot see the node's peers or its disk, because no documented method exposes either [2] [1]. The mempool is visible through txpool_content and txpool_status, but those tell you what the node is holding, not whether it is at the head. And you do not control the node.

It also cannot tell a node that is behind from a node being rate-limited into looking behind. The API reference documents 429 as "Rate limited — retry after 1 second" and 502 as "Backend node error — upstream RPC unreachable" [10]. Both are transport-level outcomes, not freshness outcomes. A throttled node is a different problem with a different fix, covered in which JSON-RPC errors are retryable.

A health predicate bounds the risk. It does not eliminate it.

What this article is not

Ordered, weighted and quorum failover is a separate decision, covered in RPC failover that actually works. So are the viem and ethers transports, which rank and retry on their own terms. No monitoring product is named or recommended here: the predicate is a few documented calls and a comparison, and you can own it.

A freshness predicate is also not sufficient on writes. A node at the head can still mishandle a nonce, and the write path — nonce, rebroadcast, the transaction you cannot retry — is a separate problem, and failover and the write path is where we take it up.

Read the API reference

Sources

  1. JSON-RPC 2.0 Specification — Extensions section — JSON-RPC Working Group (jsonrpc.org)
  2. Ethereum JSON-RPC Specification — complete method index, v1.0.0-beta.7 — ethereum.github.io (execution-apis rendered spec)
  3. net_listening — execution-apis client.yaml — ethereum/execution-apis (GitHub), src/eth/client.yaml
  4. eth_blockNumber — Ethereum JSON-RPC Specification v1.0.0-beta.7 — ethereum.github.io (execution-apis rendered spec)
  5. execution-apis BlockTag schema — definitions of latest, safe, finalized — ethereum/execution-apis (GitHub), src/schemas/block.yaml
  6. eth_syncing — Ethereum JSON-RPC Specification v1.0.0-beta.7 — ethereum.github.io (execution-apis rendered spec)
  7. Is Your RPC Node at the Chain Tip? eth_syncing — the two states that return false — SwiftNodes
  8. gRPC Health Checking Protocol — doc/health-checking.md — grpc/grpc (GitHub), doc/health-checking.md
  9. How Old Is 'finalized'? We Measured 62 Chains — stale nodes that answer correctly — SwiftNodes
  10. SwiftNodes API Reference — the only statement about 'healthy' nodes in the docs — SwiftNodes
  11. SwiftNodes Getting Started — full section list (evidence of silence on health) — SwiftNodes

This article was researched, written and edited by AI under human supervision, and checked against Rankwrite's public editorial rubric.

J
John Sullivan
Infrastructure Writer, SwiftNodes

John Sullivan covers RPC infrastructure, node operations, and multi-chain development at SwiftNodes — what it actually takes to keep endpoints fast, fresh, and reliable across EVM and non-EVM networks.

Related posts

Try SwiftNodes free — multi-chain RPC across 140 networks, flat-rate pricing, pay by card or crypto, no KYC. Get an API key in 30 seconds →