Feature by feature
Chapter 5 of 11
Realtime apps
Any deployed read query can stay open as a live subscription on web and mobile. Updates, shared records and presence rooms enforce the same access policies as an ordinary read.
In Chapter 4, myNotes.edgeql fetched a static snapshot over HTTP. Keeping two browser tabs or a mobile app synchronized with that query requires no WebSocket server or separate pub-sub bus.
Try it
Open the starter app as Ada in two browser tabs, save a note in one tab and watch it stream into the second tab immediately.
Live queries#
Pillar at work: Commit-atomic
Any deployed read query from Rules, queries and files can stay open as a live subscription over POST /subscribe. Two lines subscribe a React component to myNotes.
const myNotes = deployed<Note, Record<string, never>>('myNotes')const { rows, error, isLoading } = useLiveQuery(myNotes, {})External socket servers can race ahead of database transactions or update one component on a page before another. Napalm emits diffs strictly after commit, and every subscription on a connection advances at the same commit boundary so lists, counts and detail panes stay consistent.
One shared connection
All live queries and presence rooms on a page share one stream.
Post-commit updates
Row patches stream only after commit, so rolled-back writes never appear.
Sharing and revocation#
Pillar at work: Caller-bound
Live subscriptions evaluate the same access policy expressions as ordinary reads on every commit. To support collaborative editing on Note, add a multi editors link and a policy granting select and update to listed editors.
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);}Sharing or unsharing a note is an ordinary update query.
update Notefilter .id = <uuid>$note and .owner ?= global callerset { editors += identity_by_id(<uuid>$person) }When Ada adds Ben to .editors, the note streams onto Ben’s open list immediately. When Ada removes him, the note disappears from Ben’s screen on that exact commit without client refresh logic.
Presence rooms#
Ephemeral state such as cursor coordinates, text selections and active viewer avatars does not belong in database tables. Any readable record ID can host an in-memory presence room that writes nothing to disk.
const { people, peers, isJoined, update } = usePresence<Here>(note, { state: { name, isTyping: false } })Joining a room checks the caller’s read policy on that record. If Ada removes Ben from a shared note, Napalm evicts his connection from the presence room on the same commit.
In-memory presence
Cursors and viewer lists stay off disk under the record’s read policy.
Web and mobile clients#
Pillar at work: Compiled
The same deployed .edgeql files drive web and native mobile apps. Web apps and React Native share useSession and useLiveQuery from napalm-client/react, while Flutter apps consume typed Dart Streams generated by napalm generate. When a phone wakes from background sleep, the SDK resumes from its last commit bookmark automatically.
Live streams keep connected clients current, while external APIs, scheduled tasks and data warehouses need reliable background execution.