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.
Ordered row deliveries
Napalm delivers one signed batch at a time with deterministic row bookmarks.
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.
- Change-log storage
- Row-carrying webhooks read from the cluster’s change log (
napalm storage enable <cluster> log). - Notify triggers
- The schema declares
order_changedandproduct_changed. One webhook can subscribe to multiple events. - Service role
{ "default::role": "service" }in the endpoint’sserviceGlobals(configured in Warehouse sync).- Relay endpoint
- Any stateless HTTPS endpoint or serverless function that can publish to your broker.
- Single-shard branch
- Row-carrying webhooks run on single-shard branches. The change log does not yet cover multi-shard branches.
using extension auth;using extension napalm;using future simple_scoping; module default { global caller := global ext::auth::ClientTokenIdentity; # Set to 'service' for service keys via endpoint serviceGlobals (user sessions cannot spoof 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 row-carrying webhook#
Register the webhook with a --read-only service key so Napalm delivers committed row batches rather than empty pings.
# Create a dedicated read-only service key and note its IDnapalm 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 commit position when 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 { // Verify the HMAC signature over the raw request bytes before parsing. delivery = await readDelivery(await request.arrayBuffer(), request.headers, process.env.NAPALM_WEBHOOK_SECRET!) } catch { return new Response(null, { status: 401 }) } if (delivery.kind === 'gap') { // Publish gap markers so downstream consumers know when to reload full tables. 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) => ({ // Partitioning by object ID keeps every mutation to one record in sequence. key: row.id, // Deterministic message ID across retries so brokers and consumers can deduplicate. id: `${change.bookmark}:${index}`, body: { ...row, ...stamp }, })) : // Bulk transactions omit inline rows and list the affected schema types instead. [{ key: 'whole', id: change.bookmark, body: { types: change.types, ...stamp } }], ) } // Acknowledge with 204 only after the broker accepts the batch. 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 batch.
Ordering and deduplication#
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 relay publishes each batch on arrival.
- Partition order
- Partitioned brokers order messages within each key. Using the object
idas the key keeps every mutation to one order in sequence while independent orders process in parallel. - Retries
- Napalm redelivers a batch 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. - Multi-row commits
- Rows that committed together share a
bookmark. Consumers that need multi-row atomicity can group incoming messages bybookmark.
Configure your broker#
Most message brokers order messages within each partition key and drop duplicate publishes inside a deduplication window.
Stateless broker relay
Napalm holds the durable cursor while your relay fans rows into partitions.
Bind the relay’s object id key and deterministic bookmark:index message ID to your broker’s partitioning and deduplication fields.
| Broker | Per-object ordering | Deduplication |
|---|---|---|
| Kafka, Redpanda | Set the message key to row.id so every change to one object lands on one partition. | DeduplicationPass the deterministic ID in a header so consumers skip already-applied IDs. |
| Amazon SQS FIFO | MessageGroupId | DeduplicationMessageDeduplicationId drops duplicate publishes within five minutes. |
| Google Pub/Sub | Set the ordering key on a subscription configured for message ordering. | DeduplicationPass the deterministic ID as an attribute so consumers skip already-applied IDs. |
| NATS JetStream | Streams preserve publish order for a single active consumer. | DeduplicationThe Nats-Msg-Id header drops duplicates within the stream’s deduplication window. |
Broker deduplication windows cover immediate retries. Consumers that require strict once-only application across longer windows should record the last applied message ID per object key.
Inspect the message payload#
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- Row operation:
insert,updateordelete. fields- Post-commit field values on
insertorupdate, and pre-delete values ondelete. - Value format
- Booleans, integers and floats serialize as JSON primitives. Other scalars use PostgreSQL text format (such as timestamps, decimals and enums), and single links carry the target record’s
id. previous- Prior values for fields modified by an
update, letting consumers distinguish a refund from a routine edit. caller- Caller class and protocol source for the transaction, distinguishing agent writes over
mcpfrom end-userhttprequests. link- Multi-link and multi-property change entries name the field and list elements
added,removedorupdated.
Catch up after broker downtime#
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.
- Broker outage
- Return
500from the relay route. Napalm retries from the same log position after 10 seconds with exponential backoff up to 5 minutes. - Retention window
- Retries continue while the change log retains those commits (
napalm storage keep <cluster> log --days). - Past retention
- The next delivery emits a
gapof kindexpired, followed by rows from the oldest retained commit. Your relay publishes the gap marker so consumers reload affected tables. - Manual pause
napalm webhooks pause shop <url>holds the webhook at its current position untilnapalm webhooks resumeruns.
Check the deliveries#
Send a synthetic test
napalm webhooks test shop https:/reports the route’s response. Test deliveries carry zero transactions and publish nothing./ relay.example.com/ napalm Refund an order
Confirm one message arrives keyed by the order ID and carrying
previous.statusset toPaid.Simulate a failed publish
Force the relay route to return
500once and verify the retried batch arrives carrying identical message IDs.Compare session and service-key writes
Update an order from a buyer session and again from a service key, and confirm the two messages report different
callermetadata.
Notifications & webhooks documents every delivery field and header.