Skip to the page

First principles

Chapter 2 of 11

The six pillars

Six design rules shape every part of Napalm and compile one schema file into a verified backend.

Most databases let you drop a column while live queries still read it. Adding separate object storage, job queues and read replicas splits permissions and transactions across half a dozen systems.

Try it

Remove body from Note in your starter app and push the schema. Napalm refuses the migration before anything changes.

Your terminal
napalm schema push notes
dbschema/queries/myNotes.edgeql
InvalidReferenceError: object type 'default::Note' has no link or property 'body'
dbschema/queries/addNote.edgeql
InvalidReferenceError: object type 'default::Note' has no link or property 'body'
Nothing was applied because the new schema would break these queries. Fix the queries or the schema.
Napalm lists every saved query that reads body and leaves the database untouched.

One typed graph#

Rows, binary files (ext::files::File), search indexes (ext::ai::index), background jobs, agent grants and tenant roots all live as typed entities and links in one schema.

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);}
Notes, search indexes and binary file attachments share one typed graph.

Files, search indexes, background jobs and grants obey the same access rules and transaction snapshots as your rows without separate sync workers.

Caller-bound#

Every stored type starts closed. Napalm binds verified caller identity (global caller or service globals) inside PostgreSQL, and access rules walk links in the same EdgeQL language as queries.

dbschema/default.gel
global caller := global ext::auth::ClientTokenIdentity; type Note {  access policy owner_has_full_access    allow all    using (.owner ?= global caller);}
Permissions and queries walk links from verified caller identity.

One typed schema

Rows, files, indexes, jobs and grants share one graph in dbschema/default.gel.

Closed by default

Every stored type stays locked until an access policy opens a path from caller identity.

Those rules govern reads, writes, signed file URLs, vector search, actions, background jobs and MCP tools while planning in a fraction of the memory of nested SQL policies. Expiring rules check datetime_of_statement() without a cleanup job, and org tokens (napalm_…) manage clusters without reading customer field values.

Compiled#

Your schema and .edgeql files carry static types and cardinalities, so Napalm checks every query against the schema and access policies before anything runs.

Terminal
napalm generate notes --lang ts
Generate typed clients, CLI commands and MCP tools from checked query files.

napalm schema push rejects breaking migrations before applying changes, compiles each read and every touched policy into one SQL statement and type-checks generated /ask queries before execution.

Commit-atomic#

Every write commits or rolls back as one atomic unit across rows, queued jobs, webhooks and live subscriptions. A rolled-back write sends no webhooks, queues no jobs and changes nothing on live screens. Dry-run proposals return exact before-and-after rows and roll back.

dbschema/queries/addNoteWithReminder.edgeql
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 }
Data writes, wallet debits and delayed jobs commit together in one statement.

After commit, Napalm-Bookmark and Napalm-Position carry the commit position across reads and workers. Live queries on one screen advance at the same commit, replicas never serve state older than a caller’s writes, webhook workers read up-to-date rows and backups retain deleted files across your restore window.

Distributed from links#

Traditional sharding adds a tenant_id column to every table and every query. In Napalm, your schema declares ordinary required links while cluster topology scales underneath.

Terminal
napalm clusters scale <cluster> --engines 2 --replicas 1
Scale stateless engines and cross-zone replicas behind one unchanging address.

Topology scales beneath unchanged links

Required links co-locate each tenant’s graph so Napalm splits busy roots across shards behind one unchanging endpoint.

Required links place and move customer graphs across shards, bookmarks route reads to caught-up replicas and search indexes grow past 100 million vectors without changing a query.

Checked and fault-tested#

Napalm verifies access and durability mechanically before and after deploy. Schema pushes reject broken queries and unplaceable links before touching data.

Terminal
napalm schema push notes --reviewnapalm explain-access notes <note-id> --as ben@example.com
Verify migrations statically in CI or audit live rule traces without reading private values.

Value-blind rule traces

explain-access and people reach audit policies without exposing customer field values.

Automated fault campaigns

Every release faces bounded faults in the public chaos lab before rollout.

In production, explain-access, people reach, insights and dry-run /ask inspect permissions and query plans without changing main or exposing field values. Every release also runs automated fault campaigns in the public chaos lab. Incomplete evidence is marked Inconclusive, never Passed.

Every person, service, operator and agent enters your system through a distinct boundary.

Type a word or two to search every docs page.