---
id: I0013
title: "ClickHouse throughput loader"
url: https://carbium.sh/library/integrate/clickhouse-throughput-loader
collection: Integrations
category: Data warehouses
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# ClickHouse throughput loader

A Node job that reads the cluster's slot, block height, epoch and transaction count from Carbium RPC with one call, then inserts one row into ClickHouse over its HTTP interface. With no ClickHouse URL it prints the row instead.

## What one run does

The loader is a batch job. It starts, takes one reading of the cluster's progress, inserts it into ClickHouse as a row and exits. Run it from cron or a systemd timer and the table gains a row per run. Its only dependency is `@solana/kit`. It talks to ClickHouse with the global `fetch` over the HTTP interface, so there is no ClickHouse client library to install.

1. Build one Carbium client and read `getEpochInfo` once.
2. Turn the answer into one JSON row. With no `CLICKHOUSE_URL`, print the row and stop.
3. Otherwise create the table if it is missing.
4. Send the row in one `INSERT ... FORMAT JSONEachRow`, then exit.

The Carbium read comes before any ClickHouse call, so a failed read leaves the table as it was. A row has six columns.

| Column | Holds |
|---|---|
| observed_at | The time ClickHouse received the row, filled in by a column default. It is the table's sort key. |
| slot | The slot the node had reached, from `absoluteSlot`. |
| block_height | The node's block height. It grows a little slower than `slot`, because a skipped slot makes no block. |
| epoch | The epoch number. |
| slot_index | The slot's position inside its epoch. |
| transaction_count | The transactions the node reports as processed without error since genesis. NULL when the node leaves it out. |

## The Solana side: one call returns the reading

The loader sends its calls to `https://services.carbium.sh`. Each run is a new process, so it opens one connection and that connection closes when the run exits.

`getEpochInfo` answers with the current slot as `absoluteSlot`, the block height, the epoch, the slot's position inside it as `slotIndex`, the epoch length as `slotsInEpoch` and, when the node reports it, `transactionCount`. The loader keeps all but the epoch length. The call names no commitment, so the reading comes from the chain at confirmed commitment.

Slots last about 200 ms, so `slot` advances by about 300 in a minute. `block_height` advances a little less, since a skipped slot makes no block.

Throughput comes from two rows. Subtract the older `transaction_count` from the newer and divide by the seconds between their `observed_at` values. Mainnet blocks carry no vote transactions since the Alpenglow switch on 2026-10-21, so the count grows more slowly after that date than before. A rate chart that spans the switch shows a step down that comes from the missing votes.

Each row is one instant, and a rate is an average over the gap between two rows. A burst shorter than your run interval raises the average a little and shows nowhere else.

## The ClickHouse side

Point `CLICKHOUSE_URL` at the HTTP interface, for example `http://localhost:8123` for a local server. The user and password come from `CLICKHOUSE_USER` (default `default`) and `CLICKHOUSE_PASSWORD` (default empty) and travel in the `X-ClickHouse-User` and `X-ClickHouse-Key` headers. The loader never prints them.

The table is a plain `MergeTree` ordered by `observed_at`. Every run reads a fresh value and adds its own row, so a run that fails leaves nothing to repair and the next one carries on. The newest rows read as `SELECT observed_at, slot, transaction_count FROM solana_snapshots ORDER BY observed_at DESC LIMIT 10`.

At 1,440 rows a day, partitioning is a decision for later, once you know your queries.

## The loader

Install with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types when it loads the file. `CARBIUM_KEY` is required, and the file exits with a message when it is unset. `CARBIUM_RPC_URL`, `CLICKHOUSE_URL`, `CLICKHOUSE_USER` and `CLICKHOUSE_PASSWORD` are optional. With no `CLICKHOUSE_URL` the loader inserts nothing and prints the row it would have inserted.

`main.ts` (run: `node main.ts`)

```ts
// I0013 · ClickHouse throughput loader
// https://carbium.sh/library/integrate/clickhouse-throughput-loader
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isSolanaError,
  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,
} 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 chUrl = process.env.CLICKHOUSE_URL; // unset: print the row, insert nothing
const TABLE = "solana_snapshots";
const DDL = `CREATE TABLE IF NOT EXISTS ${TABLE} (observed_at DateTime DEFAULT now(), slot UInt64, block_height UInt64, epoch UInt64, slot_index UInt64, transaction_count Nullable(UInt64)) ENGINE = MergeTree ORDER BY observed_at`;

// One client, reused across the retries of this run.
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

async function ch(query: string, body = ""): Promise<string> {
  const res = await fetch(`${chUrl}/?query=${encodeURIComponent(query)}`, {
    method: "POST",
    headers: {
      "X-ClickHouse-User": process.env.CLICKHOUSE_USER ?? "default",
      "X-ClickHouse-Key": process.env.CLICKHOUSE_PASSWORD ?? "",
    },
    body,
    signal: AbortSignal.timeout(30_000),
  });
  const text = await res.text();
  if (!res.ok) throw new Error(`ClickHouse answered ${res.status}: ${text.slice(0, 200)}`);
  return text;
}

// Seconds a 429 asks us to wait, or 0 for any other error.
const tooMany = (e: unknown) =>
  isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && e.context.statusCode === 429
    ? Number(e.context.headers.get("retry-after")) || 1
    : 0;

// Up to 4 tries; after the fourth 429 the error ends the run with a non-zero exit.
async function reading() {
  for (let attempt = 1; ; attempt++) {
    try {
      return await rpc.getEpochInfo().send({ abortSignal: AbortSignal.timeout(15_000) });
    } catch (e) {
      const wait = tooMany(e);
      if (!wait || attempt === 4) throw e;
      console.error(`429 on getEpochInfo, waiting ${wait} s`);
      await new Promise((r) => setTimeout(r, wait * 1000));
    }
  }
}

const info = await reading();
const row = JSON.stringify({
  slot: Number(info.absoluteSlot),
  block_height: Number(info.blockHeight),
  epoch: Number(info.epoch),
  slot_index: Number(info.slotIndex),
  transaction_count: info.transactionCount == null ? null : Number(info.transactionCount),
});
if (chUrl) {
  await ch(DDL);
  await ch(`INSERT INTO ${TABLE} FORMAT JSONEachRow`, row);
}
console.log(`${chUrl ? "inserted " : ""}${row}`);
```

## Run it, then schedule it

Start with no ClickHouse at all. `node main.ts` prints one JSON row. Then set `CLICKHOUSE_URL`: the first run creates the table and inserts the row, and each run after it adds one more.

To check the table, run `SELECT count(), min(slot), max(slot) FROM solana_snapshots`. The `max(slot)` is the slot of the newest row, and it moves forward by about 300 for each minute between runs.

For a schedule, use a systemd timer that starts a oneshot service every minute with `node main.ts`. A timer does not start a second copy of a oneshot service while the first is still running, so a slow run skips the next trigger and never overlaps it. Keep the key in an `EnvironmentFile` that only that service can read.

## What it costs against your limits

Each run makes one `getEpochInfo` call, and one call a minute is a small rate next to the per-second ceilings of any plan. Check the `getEpochInfo` allowance on your plan in the [RPC method list](https://carbium.sh/docs#rpc) before you size a schedule.

Limits are [per account](https://carbium.sh/docs#limits), so the loader shares one budget with every other key you have. When a call gets a 429, the loader sleeps for the `retry-after` seconds, logs the wait and retries, up to 4 tries in all. After the fourth 429 it exits with an error and the next run takes a fresh reading, so a key held at 429 for a long time cannot keep one run going. A short rate limit slows a run and loses no reading. For alerts on those 429s, see [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts).

## Where it ends

- It stores one reading per run: cluster totals at an instant. It holds no per-block detail, transactions, accounts, instructions or logs. `getTransaction` costs [50 cells per call](https://carbium.sh/docs#rpc), which sets the budget for a loader of full transactions, a different job from this one.
- It reads the present only. A run missed while the host was down leaves a hole in time, and a later run cannot fill it.
- `observed_at` is when ClickHouse received the row, a moment after the node answered, and the wait of a retry after a 429 adds to that delay.
- `transaction_count` is the node's own counter. A rate from it covers every transaction the node counts, with no split by program or sender, and the field is NULL when the node leaves it out.
- For one address, `getSignaturesForAddress` costs 50 cells per call and reaches back 30 days at most, from Carbium's own [address index](https://carbium.sh/docs#migrate). Older history is not served.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The run stops with `ClickHouse answered` followed by a status and a message about authentication. | Set `CLICKHOUSE_USER` and `CLICKHOUSE_PASSWORD` for a user that may create the table and insert into it. A user with read access only fails on the first statement. |
| The run stops with `ClickHouse answered 400` and a message that tells you to use port 8123. | `CLICKHOUSE_URL` points at the native port 9000. That port answers an HTTP request with a 400 that names 8123 as the HTTP port. Change the URL to port 8123. |
| The run stops with `fetch failed` before any ClickHouse message. | `CLICKHOUSE_URL` does not reach an HTTP listener: the host is wrong, a firewall blocks the port or nothing listens there. ClickHouse serves HTTP on 8123 by default. HTTPS on 8443 only works once `https_port` is enabled in the server config, so an `https://` URL against a default install fails this way. Check the scheme, the port and any firewall. |
| A Carbium call fails with an HTTP error status 401. | Carbium does not know the key it received and answers 401 `UNKNOWN_KEY`, so send the whole key. Set `CARBIUM_KEY` to the full key with nothing cut off or added. The key goes in the `x-api-key` header, or as `?api-key=` on the URL. Check that nothing else sets `CARBIUM_RPC_URL`. |
| The log fills with `429 on getEpochInfo` lines and a run takes longer than the timer interval. | Compare the `getEpochInfo` allowance on your plan with your schedule. If the job needs more than your plan allows, space the runs further apart. Other keys on the account spend the same budget. |
| `transaction_count` is NULL on every row. | The node left `transactionCount` out of its answer. Run `node main.ts` with no `CLICKHOUSE_URL` to see the row it builds, and chart progress from `slot` and `block_height` instead. |

## Questions

### Why load a reading and not every block?

One call returns the whole reading, so a run stays at one call however long the job runs. A loader of every block makes one `getBlock` call per slot, and slots come about every 200 ms, which is 5 calls a second just to keep pace.

### Can it load the transactions?

Not as written, which keeps the totals per reading. `getTransaction` costs 50 cells per call, so a full load needs its own budget.

### Do I need a ClickHouse client library?

No. The HTTP interface takes the query in the URL and the rows in the body, and `fetch` can send both. A client library starts to pay off with batching, compression or a native-protocol connection.

### Why a timer and a short job?

A scheduled job has no connection to keep alive and carries on after any outage, since each run reads the present. A process that sleeps between readings does the same work with more to supervise.

## Related

- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [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#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
