services
Get a key

library / Integrations / Queues and streams / I0093

Kafka commitment-tier topics

A short Node script reads a busy program's newest signatures, checks each one's commitment twice, and prints a record per tier as topic, key and value JSON, ready for a Kafka producer, with a count for each tier.

By Carbium · Queues and streams · I0093 · updated 2026-11-22

01

What pending means on Solana

Solana has no public queue of transactions waiting for a block. A transaction goes from the sender to the current leader, and the first point where anyone outside the validator can see it is after a bank has executed it. That view is the processed commitment, so the earliest tier a topic can carry is processed. For a Kafka consumer, a stream of pending transactions is a stream of processed ones that have not yet reached confirmed or finalized.

Three topics follow from that: tx.processed, tx.confirmed and tx.finalized. A consumer that wants first sight reads the first one, and a consumer that writes a ledger reads the last. Each reads at the tier it trusts and never polls the chain to find out how settled a record is. The commitment levels entry covers what each tier promises.

The tiers sit close together. Since the Alpenglow switch on mainnet a slot lasts about 200 ms, and finalized is 0 to 1 slots behind processed. A transaction can pass through all three inside one polling pass, and one read of the three can show two of them equal or briefly out of order. The topics still carry meaning, because the tier on a record says what the producer knew when it wrote it, but plan for no wait between them.

02

Three topics keyed by signature

The record key is the transaction signature. Kafka hashes equal keys to the same partition, so inside one topic everything about one transaction stays in one place. The value is a JSON object with the signature, the slot, a failed flag and the polling pass that wrote it.

TopicWritten whenFits
tx.processedThe status is processed or higherEarly hints on a screen, anything you can take back
tx.confirmedThe status is confirmed or finalizedNotifications and balance displays
tx.finalizedThe status is finalizedLedger rows and reconciliation

A tier gets a record for every transaction that reaches it, including one first seen already finalized. That transaction produces three records in one pass, one per topic, so each topic is complete and a consumer never has to read the lower ones to fill a hole. A transaction that failed on chain still lands in a block, so it appears in the topics with failed set to true.

Separate topics have separate partitions and offsets, so there is no order between them. A consumer of tx.finalized can receive a signature before the consumer of tx.confirmed receives the same one.

The produce call stays in your Kafka client. Its send takes a topic name, a key and a JSON string, which are the three fields the script prints on each line, so moving the output into a producer is one call per line.

03

The promotion loop

Signatures come from getSignaturesForAddress on a busy program, newest first. @solana/kit 8.6.0 fills in confirmed for that call, so each listed signature is already at confirmed or higher. The call costs 50 cells, which on Free is 0.24 calls a second and on Dev is 1.2, so the script makes it once and reuses the list.

Then getSignatureStatuses runs over the whole list, and a map remembers the highest tier already produced for each signature. A pass compares the status it reads with the map and produces the missing records, lowest tier first. A second pass two seconds later promotes anything that moved. A long-running version repeats the pass until a signature is finalized or a timeout passes, then drops it from the map.

Install with npm install @solana/[email protected] and set "type": "module" in package.json. Run it with a program address, or with none for a default busy program. Each record is one JSON line on stdout, and the totals per tier go to stderr at the end.

main.ts
// I0093 · Kafka commitment-tier topics// https://carbium.sh/library/integrate/kafka-commitment-tier-topics// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, isAddress, type Signature } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY."); process.exit(1); }const program = process.argv[2] ?? "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";if (!isAddress(program)) { console.error("Usage: node main.ts [program address]"); process.exit(1); }const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({  url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",  headers: { "x-api-key": key },}));const tiers = ["processed", "confirmed", "finalized"] as const;const emitted = new Map<Signature, number>(); // highest tier index already produced per signatureconst counts = { processed: 0, confirmed: 0, finalized: 0 };async function promote(sigs: Signature[], pass: number) {  const { value } = await rpc.getSignatureStatuses(sigs).send();  value.forEach((st, i) => {    if (!st) return; // not visible yet, or on a dropped fork: produce nothing    const sig = sigs[i]!;    const seen = emitted.get(sig) ?? -1;    const reached = tiers.indexOf(st.confirmationStatus ?? "processed");    for (let t = seen + 1; t <= reached; t++) {      counts[tiers[t]!]++;      // the three fields a Kafka producer's send takes: topic, key, value      console.log(JSON.stringify({        topic: `tx.${tiers[t]}`,        key: sig,        value: { signature: sig, slot: Number(st.slot), failed: st.err !== null, pass },      }));    }    emitted.set(sig, Math.max(seen, reached));  });}const page = await rpc.getSignaturesForAddress(address(program), { limit: 20 }).send().catch((e: unknown) => {  console.error("signature list failed:", e instanceof Error ? e.message : e);  process.exit(1);});const sigs = page.map((s) => s.signature);console.error(`${sigs.length} newest signatures of ${program}`);for (const pass of [1, 2]) {  try {    await promote(sigs, pass);  } catch (e) {    console.error(`pass ${pass} failed:`, e instanceof Error ? e.message : e);  }  if (pass === 1) await new Promise((r) => setTimeout(r, 2_000));}console.error(`tx.processed ${counts.processed}, tx.confirmed ${counts.confirmed}, tx.finalized ${counts.finalized}`);

run: node main.ts [program address]

04

Idempotent consumers

Retries duplicate records, and polling repeats work, so every consumer should absorb a repeat without effect.

  • Turn on your client's idempotent producer so a retried send inside one session is stored once.
  • Dedupe on the signature within each topic. A set with an expiry of a few minutes is enough, because a signature only repeats while it is being promoted.
  • A consumer that reads two topics keeps the highest tier seen per signature and ignores a lower one that arrives late. That handles the out-of-order case across topics.
  • Treat tx.processed as a hint. If the signature never shows up in tx.confirmed within your timeout, undo whatever the hint caused.

The Kafka program account topic uses the same idea for account writes, keeping the highest slot per address. Here the ordering key is the tier.

05

Where it ends

  • Nothing exists before processed. A transaction that never reaches a leader never appears, and no tier shows it.
  • A processed record can be orphaned. A slot seen at processed can still be skipped when its fork is dropped, and the status then comes back null. The script writes no tombstone, so consumers expire processed records that never get a successor.
  • This run starts from a list that is already at confirmed or later, so tx.processed and tx.confirmed fill together on the first pass. For a true first sight, subscribe with `logsSubscribe` on the WebSocket at processed, filtered by a program mention, and feed each signature into the same loop.
  • Two seconds between passes is coarse next to a 200 ms slot, so most transactions arrive with every tier equal. Shorten the wait or move to a subscription if the gap between tiers matters to you.
  • The address index behind getSignaturesForAddress keeps up to 30 days, and an empty page past that marks its age limit. Older signatures are not served, and the status call here reads recent status only.
  • The script holds its map in memory. A restart forgets which records were produced, so treat the topics as at least once.
06

When it goes wrong

what goes wrongwhat to do
The first call fails with 401 and an unknown key message.Attach the whole key in CARBIUM_KEY. A cut-off or mistyped key is refused at the door.
The signature list call returns 429 with a retry-after hint on a Free key.Free allows 0.24 calls a second to getSignaturesForAddress. Wait the hinted time, and keep the single list call per run instead of listing on every pass.
Some signatures produce nothing on a pass.Their status came back null: not visible to the node yet, or on a dropped fork. The script skips them and tries again on the next pass. Never produce a record for a null status.
tx.finalized has the same count as tx.processed and tx.confirmed.That is the expected result for settled signatures, since finalized is 0 to 1 slots behind processed. The three counts differ only for signatures caught mid-promotion.
A consumer sees a signature on tx.finalized before it sees it on tx.confirmed.The topics have no order between them. Keep the highest tier seen per signature and ignore a lower one arriving later.
07

Questions

Why three topics and not one topic with a tier field?

Separate topics let a consumer subscribe to exactly the tier it trusts, and each topic can have its own retention. With one topic every consumer reads every record and filters.

Do failed transactions reach the topics?

Yes. A failed transaction is still in a block, so it moves through the tiers like any other and carries failed: true in its value.

Can a processed transaction disappear?

Yes. If its slot is skipped when a fork is dropped, the transaction may never confirm, and a later status read returns null. Expire processed records that get no successor.

How far apart are the tiers now?

Since Alpenglow a slot is about 200 ms and finalized is 0 to 1 slots behind processed, so the three can arrive equal or within one slot of each other.