RPC fleets: routing by method and height, rate limiting, multi-provider failover, and public endpoints

Backends have a height as well as a health state, and requests have wildly different costs. Route by method class, eject on lag, and limit by cost units.

Read the briefing
About 3 min to read 7 drills

What to remember

  1. Route by method class into separate pools. One trace call must not be able to starve balance lookups.
  2. Health must include height against an independent reference. Comparing to your own fleet's median hides a fleet-wide stall.
  3. Rate limit by cost, not by request count. A customer inside their request quota can still saturate you with wide getLogs.
  4. Cache keys need the chain and the resolved block. Otherwise you eventually serve one chain's answer to another chain's client.
  5. WebSocket subscriptions are sticky and stateful. They must be drained on deploys, and clients must resubscribe and re-fetch.

The big picture

A public or internal RPC endpoint is a load-balancing problem with two twists ordinary web traffic does not have: backends have a height as well as a health state, and requests have costs that vary by orders of magnitude within the same HTTP verb and path. Everything else, routing, rate limiting, failover, caching, WebSockets, follows from those two facts.

The mental model

Treat the fleet as several pools, not one: cheap reads, logs, and tracing/archive. Admission control decides whether a request is allowed and how much it costs; routing decides which pool serves it; health decides which members of the pool are eligible, where health includes "is this node at the network's head". Caching is the cheapest capacity you will ever add, provided the key includes the chain and the block tag.

In depth

Routing by method and validating the protocol

JSON-RPC hides everything in a POST body, so an ordinary L7 balancer sees one path and cannot help you. A production RPC edge parses the body: it knows the method, rejects malformed requests, bounds batch sizes (a batch of 1,000 eth_getLogs calls is one HTTP request), and routes by method class. Typical classes: cheap point reads (eth_blockNumber, eth_getBalance, eth_call at head), log and filter queries (eth_getLogs and the filter methods, which operators cap by block range and some clients limit by default), and tracing/archive (debug_traceTransaction, trace_*, historical eth_call). Each class gets its own pool so a heavy query cannot starve a balance lookup, and its own limits and timeouts.

Health, rate limiting, and failover

Health must be chain-aware: synced within N blocks of an independent reference, peers above a floor, and responding within a latency budget. A node that is up but 500 blocks behind returns confidently stale data, which is worse than an error; the balancer must eject on lag. Active probes plus passive outlier detection (eject on error ratio) together catch both stuck and sick nodes.

Rate limiting for RPC is cost-weighted: assign compute units per method (and per block range for log queries), and limit per API key against that budget, not against request count. Limits should return standard JSON-RPC errors with a retry hint, degrade smoothly, and be visible per client so the top talkers are known before they page you. Failover means more than one provider or region behind health-based routing, with automatic withdrawal of a bad site, because "our single provider degraded" is the most common outage class and manual failover during an incident costs an hour you did not have.

Caching and WebSockets

Most public-endpoint traffic is repeated reads of immutable data: finalized blocks, receipts, historical logs for an exact range. Those are cacheable indefinitely. Head-dependent answers (latest anything) must be short-TTL or uncached, because a reorg can invalidate them. Cache keys must include the chain id and the resolved block identifier, or you will eventually serve one chain's answer to another chain's client, which is the kind of bug that ends customer relationships. Coalesce concurrent identical misses (single-flight) so a cold key does not stampede the backends.

Subscriptions (eth_subscribe over WebSocket) are long-lived, stateful, and pin a client to one node: a node restart drops every subscription it held, so deployments must drain rather than cut, connections need per-client limits and heartbeats, and WebSocket traffic is usually served by a separate pool with different scaling behaviour than HTTP. Clients must be told to resubscribe and to re-fetch what they missed, because the protocol offers no replay.

Myths and facts

Myth: A standard HTTP load balancer is enough for JSON-RPC.

Fact: Everything is a POST to one path; without body-aware routing you cannot separate a balance read from a trace call.

Myth: Rate limit by requests per second.

Fact: Cost varies by orders of magnitude per method and per block range; limit by weighted cost or one client will saturate you inside their quota.

Myth: If the node answers, it is healthy.

Fact: Health includes sync distance from an independent reference; a lagging node serves stale answers with 200s.

Myth: Cache RPC responses by request body hash.

Fact: Only if the key resolves the block tag and includes the chain; caching a 'latest' answer or mixing chains produces wrong results.

Myth: WebSocket subscriptions can be balanced like HTTP requests.

Fact: They are sticky, stateful, long-lived connections that must be drained on deploys and resubscribed by clients.

How pros do it

  • Parse JSON-RPC at the edge: validate, bound batch size, route by method class to separate pools.
  • Make health chain-aware (sync distance, peers, latency) against an independent reference, with automatic ejection.
  • Rate limit by cost units per key and per method; expose top talkers by cost in a dashboard.
  • Cache immutable answers aggressively with chain and block in the key; single-flight the misses; keep head answers short-TTL.
  • Run at least two providers or regions with automated health-based failover and test it on a schedule.

Questions people ask

One customer is inside their request quota but saturating our nodes. What now?

Say the diagnosis first: their requests are expensive, so a request-count quota is the wrong unit. Then the fix: cost-weighted limits per key, a block-range cap on log queries, and heavy methods routed to an isolated pool. Interviewers want 'limit by cost, not by count' in your first sentence.

How do we handle a provider outage?

Health-based automatic failover to a second provider, with capacity reserved for it and the failover exercised on a schedule. Say out loud that manual failover during an incident costs the hour you do not have; that is the point being tested.

Users report inconsistent results between calls. Why?

Successive requests hit nodes at different heights. Give the three-part answer: pin a block number for a sequence of reads, use finalized or safe where the product allows, and tighten the balancer's lag threshold so 'latest' agrees across the fleet.

Why did all subscriptions break during a rolling update?

WebSocket connections were cut instead of drained. Say that subscriptions are sticky and stateful, so deploys need connection draining with a deadline and staggered restarts, and clients need documented resubscribe-and-refetch behaviour because the protocol has no replay.

Should we cache eth_call?

At a pinned block, yes: it is deterministic. At 'latest', no, unless you accept a very short TTL and can explain what a reorg does to the cached answer. Mention that the cache key must include the chain id and the resolved block.

Further reading

Drills · 7

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

What does the health check for an execution-layer RPC node behind your load balancer need to verify?

  1. Query the node's head block and compare it against an independent reference, require a peer count above a floor, and enforce a latency budget; eject if the node lags beyond a threshold. Chain-aware health is the only kind that detects stale-but-responsive nodes.
  2. A TCP connect check on port 8545. Proves the socket is open, nothing about correctness.
  3. Compare the node's height to the fleet's median height. A fleet-wide stall (for example a missed fork upgrade) makes the median wrong too.
  4. An HTTP 200 from a /health endpoint served by the sidecar. Process liveness misses the failure mode that matters: lag.
In short

Compare the node's head to an outside reference, require a peer floor and a latency budget, and eject on lag.

Why

The dangerous failure is a node that answers quickly with old data. Health must include sync distance from an independent reference; peers and latency catch the nodes on their way to that state.

The common mistake

Answering with a TCP check, a /health 200, or a comparison against the fleet's own median; all three pass a node that is confidently serving stale data.

Read the docs

2 Pick the strongest answer

Your endpoint enforces 100 requests per second per API key, and yet one customer running at 40 rps is spiking p99 latency for everyone else. What is the design flaw?

  1. The nodes need more CPU. Unbounded expensive queries will saturate any capacity you buy.
  2. The customer should use WebSockets instead. Transport does not change query cost.
  3. The limit is too high; lower it to 10 rps for everyone. Punishes cheap traffic and still allows expensive queries within the smaller quota.
  4. Rate limiting by request count ignores cost: their wide eth_getLogs and trace calls are thousands of times more expensive than a balance read. Limit by weighted cost units and route heavy methods to an isolated pool. Cost asymmetry is the defining property of RPC traffic.
In short

The limit counts requests, not cost; limit by weighted cost units and send heavy methods to their own pool.

Why

Cost-unit accounting (weight per method, plus a factor for block range or trace depth) is how commercial providers price and protect the same resource. Pair it with per-class pools so the blast radius of an expensive class is bounded.

The common mistake

Reaching for a lower global rps limit or more node capacity. Neither bounds the cost of a single wide eth_getLogs, so the same customer saturates you inside the smaller quota.

Read the docs

3 Find what's broken

Four problems in this balancer config will each become a customer-visible incident. Which lines?

upstreams:
  primary_pool:
    nodes: [node-a, node-b, node-c, node-d]
    health_check: { type: tcp, interval: 30s, unhealthy_threshold: 5 }
    lb_policy: round_robin
  archive_pool:
    nodes: [archive-a]
routing:
  default: primary_pool
  rules: []
websocket:
  upstream: primary_pool
  drain_on_shutdown: false
failover:
  secondary_provider: configured
  mode: manual
In short

Line 4 is a TCP check that cannot see lag, line 10 routes nothing by method, line 13 cuts WebSockets instead of draining, and line 16 makes failover manual.

What's broken
  • Line 4: A TCP health check with a 30 s interval and 5 failures needed cannot detect a node that is synced-behind; it also takes 2.5 minutes to eject a dead node.
  • Line 10: No routing rules: every method, including traces and wide log queries, goes to the primary pool, so one expensive request degrades all cheap reads.
  • Line 13: WebSocket connections are cut rather than drained on shutdown, so every rolling deploy drops all subscriptions at once.
  • Line 16: Failover to the second provider is manual, so the dominant outage class costs an hour of human reaction time.
Why

Round-robin (line 5) and a single archive node (line 7) are acceptable starting points; the four flagged items are the ones that show up as incidents. Health and routing bite daily, WebSocket draining bites on every deploy, and manual failover bites hardest when it matters most.

Read the docs

4 Scenario: what do you do next?

A major NFT mint starts at 18:00. From 17:58 your endpoint's error ratio climbs to 25%, latency to 6 s, and your primary provider's nodes are pegged. A large customer is threatening to leave; the mint lasts 40 minutes.

Step 1. First five minutes?

  1. Start syncing new nodes. New nodes take hours; not a mitigation for a 40-minute event.
  2. Raise all rate limits so customers can retry more. Amplifies load during saturation, which is the opposite of shedding.
  3. Ask the provider to add capacity and wait. Provider capacity will not arrive within the mint window.
  4. Declare the incident, shift read traffic toward the secondary provider and any spare regions, and apply cost-weighted shedding to the heaviest method classes so cheap reads keep working; post a status update with a next-update time. Uses the levers that exist now: capacity you already pay for and controlled degradation of the expensive classes.

Step 2. The shift helps but 8% of requests still fail; most failures are one customer's unbounded eth_getLogs loop. What now?

  1. Do nothing more; they are a large account. One account's pattern is degrading everyone, including that account.
  2. Ban the customer for the duration of the mint. Blunt; a cost limit achieves the same protection while keeping them serviceable.
  3. Enforce the block-range cap and per-key cost limits for that pattern immediately (documented limits, standard error), keeping their cheap traffic working, and tell them exactly what limit applied and the supported pagination approach. Targets the cost driver without cutting the customer off, and is defensible because the limits are published.
  4. Route their traffic to the archive pool. That pool is smaller and more expensive; it would fall over faster.

Step 3. After the event, what changes so the next mint is boring?

  1. Add a status page banner during mints. Communication is not mitigation.
  2. Buy 50% more nodes at the primary provider. Expensive standing capacity that still concentrates provider risk and does not bound expensive queries.
  3. Automatic health-based multi-provider failover with reserved headroom, cost-unit limits enforced by default, per-class pools, a launch-day protocol with customers, and load tests replaying mint-shaped traffic. Capacity, isolation, admission control, and a rehearsal for the recurring event type.
In short

Shift reads to the second provider now and shed the heaviest method classes by cost, so cheap reads keep working.

Why

Demand spikes are the recurring event in this domain. The answer interviewers want: use existing multi-provider capacity, shed by cost rather than by customer, enforce published limits, then make the failover automatic and rehearse with realistic traffic.

Read the docs

5 Design round

Design a public RPC endpoint serving 20,000 requests/second across three chains, with paying customers on tiers. Cover routing, pools, health, admission control, caching, failover, and the SLOs you would publish.

  • Mixed traffic: 80% cheap reads, 15% logs, 5% tracing/archive.
  • Two node providers plus your own bare-metal fleet.
In short

A strong answer sizes per-class pools from the traffic mix and treats cache keys (chain plus block hash) as a correctness concern.

A strong answer covers
  • Edge parses JSON-RPC, validates, bounds batches, routes by method class to per-class pools per chain.
  • Chain-aware health (sync distance vs independent reference, peers, latency) with fast ejection; capacity reserved for failover.
  • Cost-unit admission control per key and tier, published weights, standard errors, top-talker dashboards.
  • Cache immutable results keyed by chain + method + resolved block (prefer block hash), single-flight, short TTL for head reads.
  • Multi-provider and own-fleet mix with automatic health-based failover, tested; separate WebSocket pool with draining.
  • Published SLOs per method class (success ratio, latency, freshness/head lag) and internal SLOs for cache hit ratio and failover time.
  • Tradeoffs: cost of headroom vs availability, cache aggressiveness vs freshness, strict limits vs customer friction.
What a strong answer does
  • design quality: Per-class pools per chain, chain-aware health, cost-unit admission control, correct cache keys with reorg safety, automatic failover, separate WebSocket handling.
  • quantification: Traffic split turned into pool sizing and cache hit assumptions, headroom for provider loss, and stated SLO targets.
  • tradeoffs: Several with decisions: freshness vs cache, cost vs headroom, strict defaults vs customer experience, own fleet vs providers.
  • communication: Traffic model → pools → admission → caching → failover → SLOs → what would falsify the design.
Why

Strong answers derive pools from the traffic model, treat cache keys as a correctness concern, make admission control cost-based, and publish SLOs that include freshness.

Read the docs

6 Quick recall

Beyond 'the process is up', what must the balancer confirm before it sends an RPC node traffic?

In short

That the node is synced close to the network head.

Accepted

that it is synced · sync distance from head · it is at the chain head

Why

Sync distance against an independent reference (plus peers and latency); a lagging node answers with stale data and a 200.

7 Read the output

Which cache design flaw explains the bad receipt, and what else would you change while you are in there?

# cache statistics for the last hour
method                      requests   hit_ratio   avg_bytes
eth_getBlockByNumber(final)  4,210,000     0.97        1,900
eth_getTransactionReceipt    2,880,000     0.94          820
eth_getLogs(range<=1000)       310,000     0.61        9,400
eth_call(latest)             1,020,000     0.00          260
eth_blockNumber              5,400,000     0.00           12

# incident: a customer reports a receipt for a transaction that "does not exist on chain"
# cache key = sha256(method + params)
  1. The receipt was cached before finality, which is unavoidable. It is avoidable: cache receipts only at or after finality, or key by block hash so a reorg misses.
  2. The key omits the chain id (and any reorg awareness), so an answer cached for one network or for a block later reorged out can be served as current. Also, eth_blockNumber is uncached at 5.4M requests/hour, where even a 1-second TTL would remove most of that load. Chain-agnostic keys are the classic wrong-answer bug; head-ish reads are the cheapest thing to shave.
  3. eth_call at latest should be cached to reduce load. Head-dependent results should not be cached beyond a very short TTL; that is how you serve stale state.
  4. The hit ratio for eth_getLogs is too low; raise the TTL. Does not explain a wrong receipt, and log ranges are already mostly immutable.
In short

The cache key has no chain id and no reorg safety, and eth_blockNumber is not cached at all.

Why

Cache correctness for chain data rests on the key: chain id, method, params with the block tag resolved to a number or hash, and a policy that only immutable (finalized) results get long TTLs. A one-second TTL on eth_blockNumber is free capacity for a public endpoint.

Read the docs

Next lesson RPC nodes: clients, sync modes, pruning, snapshots, and what an RPC actually costs
Drill · RPC fleets
0:00

Loading…