Feature by feature
Chapter 6 of 11
Actions, jobs and webhooks
Side effects run only when permitted records save. Actions, background jobs and an ordered change log connect emails, webhooks and warehouses without polling.
Sending emails, queueing background work and syncing a warehouse usually force bad trade-offs. Workers holding broad database keys can act on records the caller cannot see. Jobs queued before a rollback fire on data that never saved, and warehouse connectors either bypass schema policies or poll tables on a timer.
In practice
Napalm guards external code with a saved query inside PostgreSQL before your handler ever wakes up. When Ben calls emailNote with the ID of Ada’s private note, he receives a 403 nothing_found error, and no email code runs. When Ada calls emailNote on that same note, the email goes out.
Actions and hosted handlers#
Pillar at work: Caller-bound
An action solves the permission problem by pairing a saved query with your handler code. PostgreSQL runs the query first under the caller’s access, and Napalm invokes your handler only when permitted records match.
select Note { title, body }filter .id = <uuid>$noteOn-demand action handlers
Handlers wake on demand and exchange the ES256 call token via call.db() for a 60-second session bound to the caller.
Query-guarded admit or refuse
PostgreSQL runs the saved query first under global caller, admitting matching rows or refusing with 403 nothing_found before the handler wakes.
The handler holds no standing database key. To write a result back, the handler exchanges the call token for a 60-second session bound to that same caller. Put a matching file in handlers/ so Napalm deploys and runs the code on demand and sleeps between calls, or point the action at your own HTTPS server.
# handlers/emailNote.ts pairs with dbschema/queries/emailNote.edgeqlnapalm handlers deploy notesJobs and schedules#
Pillar at work: Commit-atomic
Pushing to an external queue from an HTTP route risks losing jobs on a crash or running jobs after a rollback. In Napalm, jobs are records in ext::napalm::Job that commit together with user writes and run only after the transaction finalizes.
with note := (insert Note { owner := global caller, title := <str>$title, body := <str>$body }), reminder := (insert ext::napalm::Job { query := 'sendReminder', variables := <json>(note := <str>note.id), run_time := datetime_of_statement() + <duration>'24 hours', }),select note { id }Commit-atomic background jobs
ext::napalm::Job records commit atomically alongside user writes and execute as the original caller only after finalization.
A failed write leaves no queued job behind. When the scheduled time arrives, the job runs as Ada and retries carrying the same job id so your handler never sends the same email twice. Scheduled tasks without a user session, such as a morning digest, run on cron under a scoped service key.
napalm schedules add notes sendDigest '0 8 * * *' --key <key-id>Notify and webhooks#
Downstream systems that watch every change to Note need no polling loop either. Declare a notify line on the type so Napalm notifies subscribers whenever a write saves.
type Note { required owner: ext::auth::Identity; multi editors: ext::auth::Identity; required title: str; required body: str; # …search indexes and access rules notify note_changed after insert, update, delete;}Subscribed HTTPS webhooks receive a signed ping carrying a causal Napalm-Position bookmark as soon as an insert, update or delete on Note commits. Rolled-back writes send nothing.
Reading the change log#
Pillar at work: Compiled
Every saved insert, update and delete appends to an ordered branch change log. From the CLI, one command summarizes recent transactions without exposing field values.
Commit-ordered change log
Every commit appends caller kind, short ID and mutated type counts to an ordered log queried via Napalm-Position bookmarks.
When a webhook ping arrives, your worker passes that Napalm-Position as reach alongside its saved cursor and sees every write covered by the ping, even when a replica answers. No connection stays open between writes, and Napalm compiles your schema’s access rules into every page read.
curl "https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100" \ -H "Authorization: Bearer $NAPALM_KEY"Warehouse sync#
Create a dedicated read-only service key so your warehouse worker reads permitted changes without writing back.
napalm keys create notes --label warehouse --read-onlyAfter one initial copy, the worker applies each new page as changes save. Re-applying a page overwrites the same warehouse rows without harm, and if a bookmark falls behind log retention, the worker starts a fresh copy cleanly. In JSON change pages, each entry also records how the write arrived, such as http from the app, mcp from an agent or job from background work.
Ada’s personal app handles live screens, background jobs and change streams. Now whole customer companies want workspaces, roles and usage billing.