---
id: UC0001
title: "RPC rate-limit alerts"
url: https://carbium.sh/library/usecase/rpc-rate-limit-alerts
collection: Use cases
category: Developer platforms and infrastructure
revision: 2
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# RPC rate-limit alerts

Design the request budget of a Solana RPC layer before it runs out: what each method costs, which 429 numbers to alert on, how to cut request count, and a Node script that tracks all of it in a rolling 60-second window.

## The budget belongs to the account

A routing layer that returns 429 has used up a budget. On Carbium that budget is [per account](https://carbium.sh/docs#limits), and every key on the account draws from the same one. More keys add no capacity, because they share it.

A 429 means the layer is over its rate by more than a short burst, and the response carries a retry-after hint that tells you how long to hold back.

Each call costs a known number of cells by [method class](https://carbium.sh/docs#rpc), and the request rates differ by class and plan.

| Class | Methods | Cells per call | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|---|
| Cached reads | getHealth, getVersion, getSlot and 22 more | 1 | 5 | 30 | 100 | 500 |
| Account reads | getAccountInfo, getMultipleAccounts, getTokenAccountBalance and one more | 10 | 0.5 | 15 | 50 | 400 |
| Transaction lookup | getTransaction | 50 | 0.24 | 1.2 | 5 | 25 |
| Address signatures | getSignaturesForAddress | 50 | 0.24 | 1.2 | 100 | 500 |

getMultipleAccounts is priced per pubkey: 10 cells each, up to 300 pubkeys in one call on Pro and 100 below it. A 100-pubkey call costs 1000 cells (1001 with a body over 4 KiB). Because the rates are per class, a layer can sit at its limit on one class while the others are idle. A single global error count hides which class is hot.

## What to alert on

Raw error counts mix everything: a misspelt method, a bad pubkey, a timeout. The signal sits in the 429 path.

- 429 share: the 429 responses over all requests in the last 60 seconds. The script defaults to 2%. Set your own threshold once you have seen what normal traffic looks like.
- Worst method class: the class with the most 429s in the window. It points you at one row of the table above.
- Largest retry-after: the longest back-off the door asked for in the window. Watch it next to the share, and page when it keeps rising.

Alert once, then cool down. A layer in trouble returns a 429 for most requests, and a pager that fires on each one is muted within minutes. The script fires one alert and then stays quiet for five minutes. It also ignores windows with fewer than 20 requests.

## A watcher in one file

The script sits where your layer calls Carbium. Every call goes through one `rpc(body)` function, which posts JSON-RPC to the [RPC endpoint](https://carbium.sh/docs#endpoints), `https://services.carbium.sh`, with your [key](https://carbium.sh/docs#auth) attached. It reads `CARBIUM_KEY`, an optional `ALERT_WEBHOOK_URL`, an optional `ALERT_THRESHOLD` and a comma-separated `PUBKEYS` list for the demo.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY PUBKEYS=<pubkey1>,<pubkey2> node main.ts`)

```ts
// UC0001 · RPC rate-limit alerts
// https://carbium.sh/library/usecase/rpc-rate-limit-alerts
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only demo: watches the 429 share of a Solana RPC layer and alerts once per cooldown.
const key = process.env.CARBIUM_KEY;
if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const webhook = process.env.ALERT_WEBHOOK_URL;
const threshold = Number(process.env.ALERT_THRESHOLD ?? 0.02);
const pubkeys = (process.env.PUBKEYS ?? "").split(",").filter(Boolean).slice(0, 100);
const COOLDOWN_MS = 300_000, WINDOW_MS = 60_000, MIN_REQUESTS = 20;

type Call = { jsonrpc: "2.0"; id: number; method: string; params: unknown[] };
type Reply = { id: number; result?: unknown; error?: { code: number; message: string } };
type Seen = { t: number; cls: string; cells: number; hit: boolean; wait: number };

// Published cells per call: cached reads 1, account reads 10, transaction and signature lookups 50 each.
const CELLS: Record<string, number> = { cached: 1, account: 10, tx: 50, sigs: 50 };
const CLASS: Record<string, string> = {
  getAccountInfo: "account", getMultipleAccounts: "account", getTokenAccountBalance: "account",
  getTransaction: "tx", getSignaturesForAddress: "sigs",
};
const cls = (c: Call) => CLASS[c.method] ?? "cached";
const cells = (c: Call) =>
  CELLS[cls(c)]! * (c.method === "getMultipleAccounts" ? (c.params[0] as unknown[]).length : 1);

let window: Seen[] = [], lastAlert = 0;
const sleep = (s: number) => new Promise((r) => setTimeout(r, s * 1000));

async function alert(rate: number) {
  const hits = window.filter((s) => s.hit);
  const n: Record<string, number> = {};
  for (const s of hits) n[s.cls] = (n[s.cls] ?? 0) + 1;
  const worst = Object.entries(n).sort((a, b) => b[1] - a[1])[0]?.[0] ?? "none";
  const wait = Math.max(0, ...hits.map((s) => s.wait));
  const text = `429 share ${(rate * 100).toFixed(1)}% in 60 s, worst class ${worst}, largest retry-after ${wait} s`;
  lastAlert = Date.now();
  if (!webhook) return console.log("ALERT", text);
  await fetch(webhook, { method: "POST", headers: { "content-type": "application/json" },
    body: JSON.stringify({ text, rate, worstClass: worst, maxRetryAfter: wait }) });
}

async function rpc(body: Call | Call[]): Promise<Reply[]> {
  const calls = Array.isArray(body) ? body : [body];
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(url, { method: "POST", body: JSON.stringify(body),
      headers: { "content-type": "application/json", "x-api-key": key! } });
    const hit = res.status === 429;
    const wait = hit ? Number(res.headers.get("retry-after")) || 1 : 0;
    const dearest = calls.reduce((a, c) => (cells(c) > cells(a) ? c : a));
    const now = Date.now();
    window = [...window.filter((s) => now - s.t < WINDOW_MS), { t: now, cls: cls(dearest), cells: hit ? 0 : calls.reduce((n, c) => n + cells(c), 0), hit, wait }];
    const rate = window.filter((s) => s.hit).length / window.length;
    if (window.length >= MIN_REQUESTS && rate > threshold && now - lastAlert > COOLDOWN_MS) void alert(rate).catch((e) => console.error("alert failed:", e instanceof Error ? e.message : e));
    if (!hit) {
      const out = (await res.json()) as Reply | Reply[];
      const list = Array.isArray(out) ? out : [out];
      if (list.some((r) => r.error?.code === -32601)) console.error("-32601 method not found: not retrying");
      return list;
    }
    if (attempt === 1) throw new Error("still 429 after one retry");
    await sleep(wait);
  }
}

const report = (label: string) => console.log(`${label}: ${window.length} requests, ~${window.reduce((n, s) => n + s.cells, 0)} cells asked, ${window.filter((s) => s.hit).length} x 429`);
const call = (id: number, method: string, ...params: unknown[]): Call => ({ jsonrpc: "2.0", id, method, params });

for (let i = 0; i < 40; i++) await rpc(call(i, "getSlot"));
report("getSlot loop");
if (pubkeys.length) {
  window = [];
  for (const [i, k] of pubkeys.entries()) await rpc(call(i, "getMultipleAccounts", [k]));
  report("one pubkey per request");
  window = [];
  await rpc(pubkeys.map((k, i) => call(i, "getMultipleAccounts", [k])));
  report("one JSON-RPC batch");
}
```

On a 429 the wrapper reads `retry-after`, takes it as seconds (the HTTP default), waits that long and retries once. A second 429 raises an error to the caller. Every attempt is one entry in the window with its class, its estimated cells and its retry-after. A 429 books no cells. A batch is booked under the class of its dearest call. A `-32601` reply is logged and never retried.

The alert goes to the webhook as JSON with `text`, `rate`, `worstClass` and `maxRetryAfter`, and prints to the console when no webhook is set.

The demo traffic is read-only: a getSlot loop, then getMultipleAccounts over your pubkeys sent as one call per pubkey and then as a single JSON-RPC batch. It signs and sends nothing. Each phase prints its request count and the cells asked for. The cell totals match, because the script prices every call in a batch at its table cost, while the request count drops from one per pubkey to one. Swap the demo for your layer's own calls and keep `rpc` and the window.

## Spend fewer requests and cells

Caching and dropping calls cut the cells the door meters. Batching and getMultipleAccounts cut requests and round trips and leave the cells unchanged.

- Batch independent calls. One POST carries a single call or a batch of up to 100, so the request count can fall by up to 100 to 1.
- Fold account reads into getMultipleAccounts. Fifty getAccountInfo calls cost 500 cells in 50 requests. One getMultipleAccounts over the same 50 pubkeys costs the same 500 cells in one request, and takes up to 300 pubkeys (100 below Pro).
- Cache the 50-cell classes. A finalized transaction does not change, so key getTransaction results by signature and keep them.
- Never retry -32601. It means [method not found](https://carbium.sh/docs#errors): a misspelt name or a method that is not served. A retry cannot change the answer and only adds load.

## Scale by plan

Autoscaling endpoints suits a layer that fans out to many providers. Here one domain, `services.carbium.sh`, serves RPC, WebSocket and the gRPC stream, and the budget sits on the account. Another endpoint or another key draws on the budget you already have, so capacity changes when the account's plan changes.

The [plans per month](https://carbium.sh/docs#limits) are Free at $0 with 500K credits once at sign-up, Dev at $20 with 10M credits, Business at $250 with 50M and Pro at $500 with 200M. To size a change, take the class your alert names, read its row in the table above and compare your peak requests per second with the next plan's figure. The step differs by class. getSignaturesForAddress goes from 1.2 req/s on Dev to 100 on Business, and getTransaction goes from 1.2 to 5.

Changing plan is an action on your [account](https://carbium.sh/docs#account). The script does not change plans. It tells a person or your own tooling which class is over, by how much and how often, and that is the input the decision needs.

## Where it ends

- WebSockets: connection and subscription counts are capped per account by tier, and Free carries [5 sockets](https://carbium.sh/docs#websocket). A layer that opens a socket per tenant reaches that cap before any request rate. A subscription also opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent; a refused one is free. The script watches HTTP only, so count open sockets in your own layer.
- Eight methods are not served and answer -32601, among them getTokenLargestAccounts and getProgramAccountsV2. The script logs that and moves on.
- History: getSignaturesForAddress pages come from the address index, which keeps up to 30 days. An empty page past that is the index's age limit.
- The cell table in the script covers the classes in the table above. Any other method is booked at 1 cell, which is an estimate, so treat the 429 as the real answer.
- The window lives in one process. With several workers, collect the attempts in one place and compute the share there.
- Monthly credits are separate from the request rates, and the script tracks only the rate side.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The alert fires on every 429 and gets muted. | Keep the cooldown and the 20-request minimum. Alert on the share over a rolling window and page once per incident. |
| Every worker retries at the same moment after a 429, which brings the next one. | Wait the retry-after value, retry once, then return the error to the caller. With many workers add random jitter to the wait. |
| One 50-cell class is rejected, but its share of all requests stays under the threshold. | The window entries carry the class. Compute the share per class as well and alert when any class passes the threshold. |
| A new key or a second endpoint is added and the 429s continue. | Keys on one account share its budget. Read the class row in the table, cache the 50-cell classes, drop calls you do not need, or move up a plan. |
| A call that returns -32601 is retried in a loop. | Treat -32601 as final. Fix the method name, or remove a method that is not served. |

## Questions

### Does a 429 mean the request was lost?

The door refused the call and answered with a retry-after hint. Retry after that wait; the script retries once and then hands the error to your code.

### Can I add endpoints to scale out?

One domain serves RPC, WebSocket and gRPC, and all keys on an account share one budget. More endpoints or keys add no capacity, so you scale by changing the account's plan.

### Does batching lower the cells I spend?

Batching lowers the request count and leaves the cells unchanged. The script prices each call in a batch at its table cost, so treat a batch as a request-count tool.

## Related

- [Slack slot-lag alerts](https://carbium.sh/library/integrate/slack-slot-lag-alerts) (Integrations, I0001)
- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#account](https://carbium.sh/docs#account)
