← All work← Casebook 1 · Web3 engineering

PRACTICE

Blockchain RPC: Read/Write Boundaries and Safe Retries

Request timed out — switch nodes and retry? Fine for a balance read, dangerous for a broadcast: a lost response doesn't mean the chain ignored your transaction. Where safe retry ends.

Why a timeout does not automatically permit another node

Retry decisions depend on both operation semantics and the stage of failure. A read and a broadcast cannot share an unconditional retry policy. After a broadcast timeout, investigate the original operation before creating or signing another transaction.

Switching nodes is not always a safe retry. Reading a balance and broadcasting a transaction have different semantics. If a broadcast has been sent but its response is lost, creating and signing another transaction can introduce a new operation. Restarting the timer for each candidate, parsing step, or network wait can make a single request run far longer than expected. Late results after cancellation can also corrupt the caller’s state.

Implementation and tradeoffs

Decide whether switching is allowed from request semantics

Retry decisions follow semantics and failure stage
  1. Classify read, broadcast or unknown method
  2. Determine whether it was sent
  3. Retry only within the remaining budget
  4. Investigate unknown outcomes

Candidate changes do not reset the deadline; cancellation and completion share one terminal outcome.

Distinguish reads, broadcasts, and unknown methods explicitly. Queries that are safe to retry enter the appropriate candidate flow. For broadcasts or operations with unclear semantics, allow fallback only when it is certain that no network request has yet been sent. Unknown outcomes go to investigation and recovery.

Share one deadline across the request

Parsing, candidate attempts, and retries consume the same operation deadline rather than receiving a full timeout after each switch. Coordinate cancellation state with final completion so a late response from an old candidate cannot modify a request that has already ended.

Separate managed gateway requests from third-party RPC

Validate the destination and request path for managed gateways before applying the corresponding authentication context. Keep third-party RPC requests on their own request path without forwarding private authentication material. Preserve chain-specific read and broadcast boundaries, and avoid hiding configuration errors behind unconditional fallback.

Testing the mechanism

Control candidate completion order and inject cancellation before and after completion. Assert one deadline and one terminal result. Exercise reads, broadcasts, and unknown methods separately rather than using a successful read to validate all retries.

Test the routing and authentication paths

Cross-platform design requires separate failure state, request ownership, and authentication scope for the main API and RPC. Backend owners must establish equivalence between alternate endpoints.

A useful gateway test seam is the actual executor: inject a restorable network session into the actual executor so production routing and authentication decisions remain in the path while transport is replaced. Process-wide overrides require an explicit serial-test assumption and restoration after errors.

One test asserted that third-party requests carried no authentication. It passed even after the authentication guard was temporarily changed: an earlier routing decision had already classified the request as passthrough, so the guard was never reached. This assertion checked the passthrough classification. Testing the later authentication guard requires a request that reaches that branch and an assertion that fails when the guard is removed.

ENGINEERING SCENARIO

Key engineering scenarios

Illustrative scenarios · not real product interfaces

A read request cannot connect

Try another candidate within the remaining budget

A query may select another node under explicit rules, but previous waits have already consumed part of the current request’s time budget.

Handling principleKeep the same deadline and check whether another attempt is still permitted.

The broadcast response is lost

Do not resend an operation with an unknown outcome

Once a request has been sent, a missing response does not prove that a node rejected or never accepted the transaction.

Handling principlePreserve the unknown state and hand off to outcome investigation and recovery.

Cancellation races with a candidate’s completion

Accept only a valid completion for this operation

A candidate’s late response can race with cancellation from the caller. Both paths must not complete the same operation.

Handling principleCoordinate cancellation and completion ownership, rejecting stale callbacks.

  1. Classify the request and its retry semantics
  2. Establish one deadline for the operation
  3. Run candidate requests and coordinate cancellation
  4. Return the result or investigate an unknown outcome

Expand a scenario to explore its state and how it is handled.

← All work