Guides · Integrations
Queues & streams
Forward committed changes to Kafka, SQS, Pub/Sub or NATS in commit order through a lightweight relay without running a database connector.
- API
- —
- In the schema
- —
What you’ll build#
You will publish every committed change to a shop’s orders and products onto a queue or stream: Kafka, Amazon SQS, Google Pub/Sub or NATS. Napalm sends each committed stretch of the change log to a stateless HTTPS relay route you own, which publishes one keyed message per row. Downstream services that already consume the queue receive your changes with no connector daemon to run and no replication slot to watch.
Commit-ordered log deliveries with deterministic IDs
Signed rows deliveries advance along the branch’s GET /changes commit rail one batch in flight at a time, stamping every row with its causal bookmark and operation.
Before you start#
Enable cluster change-log storage, declare notify triggers on the watched types and prepare a stateless HTTPS route that can publish to your broker.
- A change log
- Rows come from the cluster’s change log:
napalm storage enable <cluster> log. - A notify on each type
- The schema declares
order_changedandproduct_changed. A webhook can follow several events. - The service role
{ "default::role": "service" }in the endpoint’sserviceGlobals. Warehouse sync shows the setting.- A route
- Any HTTPS endpoint that can publish to your queue. A serverless function is enough.
- A branch on one shard
- Row-carrying webhooks support single-shard branches. The change log does not yet cover branches spread across multiple shards.
using extension auth;using extension napalm;using future simple_scoping; module default { global caller := global ext::auth::ClientTokenIdentity; # 'service' for a service key, set in the endpoint's serviceGlobals. A session can't set it. global role: str; scalar type OrderStatus extending enum<Pending, Paid, Refunded>; type Product { required name: str; required description: str; required price_cents: int64; required is_listed: bool { default := true; }; notify product_changed after insert, update, delete; access policy anyone_reads_listed allow select using (.is_listed); access policy service_has_full_access allow all using (global role ?= 'service'); } type Order { required buyer: ext::auth::Identity; required product: Product; required total_cents: int64; required status: OrderStatus { default := OrderStatus.Pending; }; required place_time: datetime { readonly := true; default := datetime_of_statement(); }; notify order_changed after insert, update, delete; access policy buyer_can_read_and_place allow select, insert using (.buyer ?= global caller); access policy service_can_read_and_update allow select, update using (global role ?= 'service'); }}Add a webhook that carries rows#
Register the webhook with a --read-only service key so Napalm delivers committed row batches rather than empty pings.
# The key the rows are read as. It can only read. Note its id.napalm endpoint shop --passthrough keysnapalm keys create shop --label queue-relay --read-only napalm webhooks hosts shop --add relay.example.comnapalm webhooks add shop https://relay.example.com/napalm \ --event order_changed --event product_changed --key <key-id>The key’s access rules govern the queue’s contents. Any row hidden from the key is omitted at the source, so downstream consumers never have to scrub restricted records. Delivery starts from the moment the webhook is created.
Publish each change#
Verify the raw-byte HMAC with readDelivery, map each committed row to a broker message keyed by object id, and return 204 only after the broker accepts the batch.
// src/app/hooks/napalm/route.tsimport { readDelivery, type Delivery } from 'napalm-client'import { queue } from '@/lib/queue' export async function POST(request: Request) { let delivery: Delivery try { // Checked against the raw body, before anything reads it. delivery = await readDelivery(await request.arrayBuffer(), request.headers, process.env.NAPALM_WEBHOOK_SECRET!) } catch { return new Response(null, { status: 401 }) } if (delivery.kind === 'gap') { // The log couldn't give a stretch. Consumers are told, so each can read its types whole. await queue.publish([{ key: 'gap', id: `gap:${delivery.position}`, body: { gap: delivery.gap } }]) } for (const change of delivery.transactions ?? []) { const stamp = { bookmark: change.bookmark, commit_time: change.commit_time, caller: change.caller } await queue.publish( change.has_every_row ? change.rows.map((row, index) => ({ // The queue keeps one key's messages in order: one object's changes arrive as they were made. key: row.id, // The same on every repeat of this change, for the queue or a consumer to drop one by. id: `${change.bookmark}:${index}`, body: { ...row, ...stamp }, })) : // Too many rows to list. It names the types instead. [{ key: 'whole', id: change.bookmark, body: { types: change.types, ...stamp } }], ) } // Only once the queue has them. An answer that isn't 2xx has the same stretch sent again. return new Response(null, { status: 204 })}The relay route stores zero cursor state. Because non-2xx responses leave the webhook’s position unchanged, any failed broker publish automatically replays the exact same stretch.
Handle order and repeats#
Single-flight webhook delivery paired with object-keyed broker partitions preserves per-record causality without global consumer locks.
- Commit order
- Deliveries arrive in commit order, one in flight at a time. The route publishes each delivery on arrival.
- Order in the queue
- A partitioned queue orders messages within each key. Using the object
idas the key keeps every mutation to one order in sequence while letting independent orders process in parallel. - Repeats
- A stretch is redelivered if a broker publish fails or a network response drops. Combining
change.bookmarkand the row’s index produces an identical message ID on every retry. - One transaction, several messages
- Rows that committed together share a
bookmark. A consumer that needs multi-row atomicity groups incoming messages bybookmark.
Set up each queue#
Bind the relay’s object id key and deterministic bookmark:index message ID to your broker’s native partitioning and deduplication fields.
Stateless relay to partitioned queues and streams
Napalm holds the durable change-log cursor on the branch while your HTTPS relay fans committed rows out into Kafka, SQS FIFO, Pub/Sub or NATS JetStream.
| Queue | Keep an object’s changes in order | Drop a repeat |
|---|---|---|
| Kafka, Redpanda | The message key. One key always lands on one partition. | Drop a repeatCarry the id as a header. Consumers skip ids already applied. |
| Amazon SQS FIFO | MessageGroupId | Drop a repeatMessageDeduplicationId. The queue drops a repeat within five minutes. |
| Google Pub/Sub | An ordering key, on a subscription with ordering on. | Drop a repeatCarry the id as an attribute. Consumers skip ids already applied. |
| NATS JetStream | A stream keeps publish order. Read the stream with one consumer at a time. | Drop a repeatThe Nats-Msg-Id header. The stream drops a repeat within the stream’s duplicate window. |
A queue’s deduplication window covers a quick retry. A consumer that must never apply a change twice stores the last applied id for each key.
Read each message’s body#
Each published message carries the row’s operation, post-commit fields, changed previous values and transaction metadata.
{ "type": "default::Order", "op": "update", "id": "8f2c1e64-0b7a-4f4e-9d2b-3a6c5e1f7d90", "fields": { "id": "8f2c1e64-…", "buyer": "3d5a9c1e-…", "product": "b7e2f0a4-…", "total_cents": 4200, "status": "Refunded", "place_time": "2026-11-10 07:58:12.431+00" }, "previous": { "status": "Paid" }, "bookmark": "2026.11.1:7312845091331:1:0/1A2B3C4D", "commit_time": "2026-11-10T08:00:00+00:00", "caller": { "kind": "session", "via": "http" }}op- The operation on the object:
insert,updateordelete. fields- The object after an insert or update, and before a delete.
- Values
- Booleans, integers and floats are JSON values. Every other value is text in PostgreSQL’s output format, such as a datetime, a decimal or an enum value. A single link, like an order’s
buyer, is the linked object’sid. previous- For an update, each changed field’s prior value, so consumers can distinguish a refund from a routine edit.
caller- The caller kind and source for the transaction, so consumers can distinguish an agent write from a user write.
link- A row for a multi link or multi property names the link or property and carries the element
added,removedorupdated.
Catch up when the relay falls behind#
Napalm buffers undelivered transactions in the cluster’s change log and emits an explicit gap envelope if the relay stays offline past the retention window.
- Queue outage
- The route returns 500. Napalm retries from the same position after 10 seconds, then at growing intervals up to 5 minutes.
- Retry window
- Retries continue while the change log keeps those rows.
napalm storage keep <cluster> log --dayssets the retention. - After the window
- The next delivery is a gap of kind
expired, followed by rows from the oldest readable point in the log. The route publishes the gap, and consumers reread the affected types in full. - Pausing
napalm webhooks pause shop <url>holds the webhook at the current position.resumecontinues from that position.
Check the deliveries#
Send a test
napalm webhooks test shop https:/reports the route’s response. A test carries no transactions and publishes nothing./ relay.example.com/ napalm Refund an order
One message arrives, keyed by the order’s id, with
previous.statusset toPaid.Make the route fail once
The same stretch arrives again with the same message ids.
Change an order as a buyer and then with a key
The two messages differ in
caller.
Notifications & webhooks documents every delivery field and header.