---
id: BI0032
title: "RPC latency CI gate"
url: https://carbium.sh/library/blockchainideas/rpc-latency-ci-gate
collection: Blockchain ideas
category: Developer tools
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# RPC latency CI gate

You get a pipeline step that times read calls against Carbium, takes the p90 per method and exits non-zero past 400 ms, so the build fails. It needs no managed service, only a key, Node 24 and one TypeScript file.

## Who uses it

A team that ships a wallet backend, an indexer or a payment service usually has a latency promise to its own users. A deploy that adds a hop, a proxy or a bad region can break that promise while every unit test stays green. The gate catches it in the pipeline, before the release, as a red build with the number that tripped it.

A platform engineer owns the step. A developer sees only a pass or a fail and one printed line per method. A hackathon team can run the same file as a smoke check before a demo, to learn from the venue's network whether the endpoint answers in time.

The probe is a plain program. It runs on the CI runner you already have and talks to `https://services.carbium.sh` with one key, so there is no agent to install and no dashboard to log in to.

## What the gate measures

Each run times three read calls one at a time: `getSlot`, `getHealth` and `getVersion`. For every method it takes 20 samples after one discarded warm-up call, sorts them and reads the p90 by nearest rank, which is the 18th smallest of 20. If any method's p90 is over the limit, or any call errors, the process exits with code 1.

The number is the time from your runner to the endpoint and back, including the runner's own network. It is the latency your service would see if it ran where the runner runs, which is the number a latency promise is made on.

All three methods are cheap cached reads at 1 cell each. A class absorbs bursts up to 1,024 cells, so one run of 63 calls fits inside the burst on every plan. The gap between calls protects the account's shared budget when other jobs or parallel pipelines draw on it at the same time.

| Plan | Cheap reads, req/s | Gap between calls that fits |
|---|---|---|
| Free | 5 | 250 ms (4 calls/s), the default in the code |
| Dev | 30 | 50 ms (20 calls/s) |
| Business | 100 | 20 ms (50 calls/s) |
| Pro | 500 | 10 ms (100 calls/s) |

Set the gap with `GAP_MS`. Limits are per account, so a deploy that runs several pipelines at once, or other tools on the same keys, draw on one budget. Leave room for them.

## The build

The probe is one file that needs `@solana/kit` and what Node 24 ships. It is read-only: no private key, nothing sent.

1. Read `CARBIUM_KEY` and exit with a message when it is unset. Read the limit from `P90_MS` (400 by default), the sample count from `SAMPLES` (20) and the gap from `GAP_MS`.
2. Create one RPC client with the key in the `x-api-key` header and reuse it for every call. A reused client keeps its connection open, so the TLS handshake is paid once.
3. For each method, make one warm-up call, drop its time and wait the gap. Then time each call with `performance.now()`, wait the gap and keep going. A call that throws is recorded, never timed.
4. Compute the p90 from the sorted times. Print one line per method with the p90, the median, the count of errors and PASS or FAIL.
5. Print one JSON line with every result, so the pipeline can store it as an artifact, and exit 1 if any method failed.

`main.ts` (run: `CARBIUM_KEY=<YOUR_KEY> P90_MS=400 node main.ts`)

```ts
// BI0032 · RPC latency CI gate
// https://carbium.sh/library/blockchainideas/rpc-latency-ci-gate
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const limitMs = Number(process.env.P90_MS ?? 400);
const samples = Number(process.env.SAMPLES ?? 20);
const gapMs = Number(process.env.GAP_MS ?? 250); // 4 calls/s, under Free's 5 req/s for cheap reads

// One client for the whole run, so the TLS handshake is paid once.
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

// getSlot reads at confirmed, the commitment @solana/kit 8.6.0 fills in.
const probes: Record<string, () => Promise<unknown>> = {
  getSlot: () => rpc.getSlot().send(),
  getHealth: () => rpc.getHealth().send(),
  getVersion: () => rpc.getVersion().send(),
};

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
// Nearest rank: with 20 samples this is the 18th smallest.
const pct = (xs: number[], q: number) => [...xs].sort((a, b) => a - b)[Math.ceil(xs.length * q) - 1];

async function main(): Promise<void> {
  const results: Record<string, unknown>[] = [];
  let failed = false;
  for (const [name, probe] of Object.entries(probes)) {
    const times: number[] = [];
    const errors: string[] = [];
    await probe().catch(() => undefined); // warm-up, never timed
    await sleep(gapMs);
    for (let i = 0; i < samples; i++) {
      const t0 = performance.now();
      try {
        await probe();
        times.push(performance.now() - t0);
      } catch (e) {
        errors.push(e instanceof Error ? e.message : String(e));
      }
      await sleep(gapMs);
    }
    const p90 = times.length ? pct(times, 0.9) : Infinity;
    const ok = p90 <= limitMs && errors.length === 0;
    if (!ok) failed = true;
    console.log(`${ok ? "PASS" : "FAIL"} ${name} p90 ${p90.toFixed(0)} ms, median ${times.length ? pct(times, 0.5).toFixed(0) : "n/a"} ms, ${errors.length} errors, limit ${limitMs} ms`);
    if (errors.length) console.log(`  first error: ${errors[0]}`);
    results.push({ method: name, p90, samples: times.length, errors: errors.length, ok });
  }
  console.log(JSON.stringify({ limitMs, results }));
  process.exit(failed ? 1 : 0);
}

await main();
```

In @solana/kit 8.6.0 a call that leaves commitment out is filled in as confirmed, so `getSlot` reads at confirmed. The other two take none. Because every call goes out one at a time, each sample is one round trip with no other load from the probe.

Wire the step in after the deploy to a staging environment and before the promote step. Store the key as a CI secret named `CARBIUM_KEY`, set `P90_MS=400`, and run `node main.ts`. The step passes when the process exits 0. A job that cannot see the secret, as pull-request builds from forks often cannot, exits at once with the `Set CARBIUM_KEY` message.

## What it costs

One run makes 63 calls: 21 per method, counting the warm-up. A pipeline that runs 100 times a day makes 6,300 calls a day. Credits meter RPC work, each paid month adds credits and unspent credits stay. Free is $0 with 500K credits once, at sign-up, and Dev is $20 with 10M a month.

The time is the other cost. At the default 250 ms gap a run takes about 15 seconds plus the round trips. On Dev the gap can drop to 50 ms and the run to a few seconds, which is more pleasant in a pipeline that runs on every commit.

## What to add next

- A history: write the JSON line to your build artifacts and compare the p90 with the median of the last 20 runs, so the gate also fails when the p90 rises well above its recent median, even under the absolute limit.
- More methods: add `getAccountInfo` for an address your service reads. It costs 10 cells and Free allows 0.5 req/s, so a gap of 2 seconds on Free protects a budget shared with other jobs.
- Several regions: run the same step from runners in each region you serve and gate each one with its own limit.
- An alert: send the JSON line to a channel when a run fails, next to the [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) you may already have.

## Where it ends

- It is a sample taken at one moment and does not watch the endpoint between runs. For a long pipeline, raise `SAMPLES` and start it as a background step, or run it before and after the slow stage.
- Twenty samples is a small set. With 20, two slow calls still pass and three fail, so one noisy neighbour on a shared runner can flip the result. Raise `SAMPLES` to 50 or more where the limit is tight.
- It measures read calls. A pass says nothing about how long a sent transaction takes to land, and the file never sends one.
- Cached reads and heavier reads can differ. A pass on `getSlot` does not prove the p90 of `getTransaction` or `getAccountInfo`, so add the calls your service makes.
- The result includes your runner's network. A runner in another region than your service gives a number your service would never see.
- Carbium serves the endpoint. Storing history, charting it and alerting on it stay in your own pipeline tools.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The p90 changes a lot from run to run. | Raise `SAMPLES` to 50 or more and run the step on the same runner pool each time. A shared runner under load adds its own delay to every call. |
| Every call fails with 401. | The key is truncated or wrong. Attach the whole key to the job. |
| Calls answer 429 or the p90 jumps with no deploy. | Another job shares the account's budget or the gap is under your plan's rate. Widen `GAP_MS` to the table's value and check what else runs on the same keys. |
| The first call is slow and the gate fails on it. | The warm-up call exists for this. If you remove it, the TLS handshake counts in the sample. Keep one client for the whole run. |
| `getHealth` throws and the build fails. | The error text is printed. A health call that errors is a real signal that the endpoint is not answering as healthy. Check the message before you retry the build. |
| The gate never fails, even on a slow deploy. | Prove it once on a throwaway branch with `P90_MS=1`. The step must go red. |

## Questions

### Is there a managed service that times the calls and fails the build?

No, Carbium does not run the benchmark for you. You run this step in your own pipeline against the endpoint at `services.carbium.sh`. One file, one key and the exit code are enough, and the result stays in your own CI.

### Why the p90 and not the average?

An average hides the slow tail that users notice. A p90 of 400 ms says nine calls in ten came back inside that time.

### Will it run on the Free plan?

Yes. The default gap of 250 ms is 4 calls per second, under the 5 req/s that Free allows for cheap cached reads. A run takes about 15 seconds plus the round trips.

### Can I gate the time a transaction takes to land?

Not with this file. It reads and never sends. Landing time needs a signed transaction and a confirmation read, which belongs in a separate step with a test wallet.

## Related

- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [Grafana network metrics](https://carbium.sh/library/integrate/grafana-network-metrics) (Integrations, I0017)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
