Skip to the page

Feature by feature

Chapter 5 of 11

Realtime apps

Any saved query can stay open as a live subscription across web and mobile. Live updates, sharing and presence obey the same access rules as an ordinary read.

Keeping collaborative screens current usually means polling on a timer or running a separate WebSocket server. Every write route must remember to publish an event, and that second server must duplicate your database’s access rules.

Try it

Live updates stream straight from your saved queries without a second server. Open the starter notes app as Ada in two browser tabs, save a note in the first tab and watch it appear in the second.

Live queries#

Pillar at work: Commit-atomic

Any saved query from Rules, queries and files can stay open as a live subscription. Two lines subscribe the notes screen to myNotes.

src/Notes.tsx
const myNotes = deployed<Note, Record<string, never>>('myNotes')const { rows, error, isLoading } = useLiveQuery(myNotes, {})
Two lines keep Ada’s notes list current as changes are saved.

Multiplexed SSE conduit

One long-lived POST /subscribe channel multiplexes every open live query and presence room on the page.

Commit-ordered live patches

Saved queries emit atomic ID-based patches only after a transaction commits, so rolled-back writes never reach open screens.

Separate socket servers often race ahead of database commits or update one widget on a page before another. Napalm pushes changes only after commit, so rolled-back writes never flicker on screen. Every live query on a page advances at the same commit, keeping lists and detail views in sync.

Sharing and revocation#

Pillar at work: Caller-bound

Sharing a note with Ben takes one editors link and one extra rule on the Note type from Rules, queries and files.

dbschema/default.gel
function identity_by_id(target: uuid) -> optional ext::auth::Identity  using (select ext::auth::Identity filter .id = target); type Note {  required owner: ext::auth::Identity;  multi editors: ext::auth::Identity;  required title: str;  required body: str;   access policy owner_has_full_access    allow all    using (.owner ?= global caller);  access policy editors_can_read_and_change    allow select, update    using ((global caller in .editors) ?? false);}
Add multi editors and one policy to open shared notes for reading and editing.

Sharing a note with Ben is now an ordinary update.

dbschema/queries/shareNote.edgeql
update Notefilter .id = <uuid>$note and .owner ?= global callerset { editors += identity_by_id(<uuid>$person) }
Only the note’s owner can add Ben as an editor.

As soon as Ada saves the share, the note appears on Ben’s open screen. When Ada removes Ben, the note vanishes from his screen at that exact commit because live subscriptions walk the same caller-bound rules as every other read.

Presence#

Live cursors and viewer lists do not belong in database tables. Every record has an in-memory presence room that writes nothing to disk.

src/Viewers.tsx
const { people, peers, isJoined, update } = usePresence<Here>(note, { state: { name, isTyping: false } })
Join a note’s presence room as the signed-in person.

In-memory presence rooms under read rules

Live viewers and cursors stay off disk while enforcing the record’s select policy, evicting removed editors on the same commit.

Joining a room still checks read access on that note. When Ada removes Ben from the note, Napalm evicts him from the room at the same moment.

Web and mobile#

Pillar at work: Compiled

Those same saved query files power phones and tablets without extra backend code. Web apps and React Native share the same useSession and useLiveQuery hooks from napalm-client/react, while Flutter apps subscribe to typed Dart streams compiled straight from your query folder. Every screen on every device stays current under one set of rules.

Next, trigger emails, webhooks and background jobs only after writes commit.

Type a word or two to search every docs page.