First principles
Chapter 2 of 11
The six pillars
Six architectural rules hold across every feature in Napalm. Together, those rules keep access, transactions and shard placement consistent as your app grows.
Compiling your backend from a single schema works because Napalm enforces six rules across the compiler and runtime, from your first local migration to multi-shard failover.
Try it
Remove body from Note in your starter schema and run napalm schema push. Napalm checks every deployed query first and refuses the migration before anything changes.
One typed graph#
Application tables, binary files (ext::files::File), vector and full-text indexes (ext::ai::index, fts::index), background jobs (ext::napalm::Job) and permission grants all live as typed objects and links in dbschema/default.gel.
type Note { required owner: ext::auth::Identity; required title: str; required body: str; deferred index ext::ai::index(embedding_model := 'openai/text-embedding-3-small') on (.title ++ '\n\n' ++ .body); index fts::index on (( fts::with_options(.title, language := fts::Language.eng, weight_category := fts::Weight.A), fts::with_options(.body, language := fts::Language.eng, weight_category := fts::Weight.B) ));} type Attachment extending ext::files::File { required owner: ext::auth::Identity; access policy owner_has_full_access allow all using (.owner ?= global caller);}Full-text indexes and queued jobs commit inside the write transaction, while deferred vector embeddings refresh in the background. Every search, download and job enforces the same schema access policies without external sync workers.
Caller-bound#
Every stored object type starts closed over the API. Napalm verifies each bearer credential, binds global caller or configured service globals inside PostgreSQL, and evaluates access policy expressions in the same EdgeQL language as your queries.
global caller := global ext::auth::ClientTokenIdentity; type Note { access policy owner_has_full_access allow all using (.owner ?= global caller);}One policy governs HTTP queries, live streams, signed file downloads, vector search, actions, jobs and MCP tools. Time-limited rules check datetime_of_statement() on the statement clock, and org tokens (napalm_…) manage clusters without reading row values.
Closed by default
Types without a matching policy return zero rows and refuse writes.
Verified identity
Napalm binds the caller identity inside PostgreSQL before any query runs.
Compiled#
Every EdgeQL expression carries a static type and cardinality. When you push changes, the compiler checks your schema, access policies and saved .edgeql query files together before applying DDL.
napalm generate notes --lang tsSaved queries compose dynamic UI filters and cursors with typed optional parameters, while POST /query runs parameterized ad-hoc statements and /ask compiles plain-English questions read-only. In every path, the compiler lowers the query and its touched policies into a single SQL statement without N+1 round trips.
Commit-atomic#
Row changes, ledger updates and queued ext::napalm::Job records commit or roll back together in one PostgreSQL transaction. Live query patches, notify webhooks and file upload windows fire only after commit, so rolled-back writes and dry-run previews emit nothing.
with note := (insert Note { owner := global caller, title := <str>$title, body := <str>$body }), job := (insert ext::napalm::Job { query := 'sendReminder', variables := <json>(note := <str>note.id) }),select note { id }Committed responses return Napalm-Bookmark, and webhook pings carry Napalm-Position. Replicas and downstream workers wait for that commit position before reading, so callers never observe stale rows after their own writes.
Distributed from links#
Conventional sharding forces you to copy a shard key across every table, foreign key and query. In Napalm, the compiler walks required single links upward to infer placement roots for any domain hierarchy (Account, Project, Organization or Site). ext::napalm::root annotations mark explicit roots, replicate lookup tables across shards or exclude secondary links from ownership. User identities (ext::auth::Identity) and multi links never claim shard ownership, so multi-org memberships and guest collaborators span roots freely.
Sharding from links
Required links group related records on one shard without shard-key columns.
Every table keeps a standard uuid primary key. Shards split and rebalance behind one project URL, bookmarks route reads to caught-up replicas and vector indexes scale past 100 million embeddings without query changes.
Checked and fault-tested#
Static checks block breaking migrations and unplaceable root links before deploy, while runtime diagnostics verify permissions and durability under load.
napalm schema push notes --reviewnapalm explain-access notes <note-id> --as ben@example.comIn production, napalm explain-access, napalm people reach, napalm insights and dry-run /ask inspect permissions, reachable row counts, per-policy latency and index recommendations safely. Every release also runs automated fault campaigns on the public chaos lab, where incomplete evidence is marked Inconclusive rather than Passed.
Policy diagnostics
Inspect live permissions and reachable row counts without reading field values.
Release fault tests
Every release faces crashes, network splits and full disks before rollout.
Before writing our first access policy, let’s look at how orgs, clusters, branches and credentials fit together.