Learn · Scale & operations
Scale & recovery
Add engines, replicas and shards behind the same endpoint without changing your schema or queries.
- In the schema
- —
Independent scaling#
Scale each tier of a cluster independently from the console, CLI or Clusters API. Your schema, access policies and generated SDKs stay identical as traffic grows.
- Engines
- Stateless engines scale connections, query compilation, live streams and read caching.
- Replicas
- Cross-zone replicas serve causal reads and stand ready to take over writes.
- Horizontal shards
- Data shards partition root subtrees across multiple primaries as writes and storage grow.
Engines#
Napalm engines serve HTTPS, SSE, MCP and A2A traffic, compile EdgeQL, cache reads and push live query patches. Adding engines expands connection and CPU capacity behind your project’s hostname.
Read replicas#
Hot PostgreSQL replicas in separate availability zones serve read queries under your full access policies, and the primary handles writes. Causal Napalm-Bookmark headers ensure replicas never serve reads older than a caller’s own commits. See Replica read routing.
Root-partitioned shards#
Add horizontal shards when write volume or dataset size outgrows a single primary. Each shard is an independent PostgreSQL group with a dedicated primary and replicas. Using placement roots inferred from required single links or declared with ext::napalm::root (such as Account, Project, Site, World or Organization), Napalm places each root record and its rooted descendants on one shard without composite primary keys or manual sharding columns. Links to ext::auth::Identity, multi links and links marked ext::napalm::root := 'none' never claim shard ownership, so multi-org memberships and cross-root references span shards freely. Single-root queries route straight to the owning shard, and buckets or individual roots rebalance online behind the same project URL. See Horizontal sharding and rebalancing below and the Distribution API.
Horizontal sharding and rebalancing#
Enabling root placement (napalm placement enable) records every row’s owning root without changing table schemas, foreign keys or UUID primary keys. Each root is assigned once at creation to a numbered bucket in the branch’s versioned placement map (GET /), and every rooted child row along that root’s link tree inherits the same bucket.
The placement map assigns contiguous bucket ranges to participating data shards, starting with every bucket on the branch’s base shard. Splitting a shard divides that shard’s bucket range onto a new shard, and rebalancing moves numbered buckets between shards without altering record IDs. A root override places one root UUID on a dedicated shard apart from the rest of its bucket. Overrides isolate a high-traffic root (such as a busy workspace, game world or enterprise organization) or keep a root inside a geographic region. Engines cache the active map version and refresh the placement map automatically on a stale-bucket retry before any statement commits.
Query routing, reference tables and core copies#
Napalm routes each compiled statement from its read set, write set, query filters and access policy expressions rather than broadcasting scatter-gather fan-out queries across data shards.
Single-root routing
Stateless engines route single-root statements straight to the owning shard without fan-out.
Continuous streaming
Data shards stream commits to read replicas and analytical core copies.
Each statement shape maps to a fixed execution target so multi-shard branches avoid cross-shard locks and scatter-gather latency.
| Workload pattern | Execution target | Architectural tradeoff |
|---|---|---|
| Single-root reads and writes | Owning shard primary or causal replica | Architectural tradeoffStatements pinned by $param, object ID or a root policy global run as local single-shard PostgreSQL transactions with zero cross-shard network hops. |
Shared lookup joins (reference) | Local copy on every shard | Architectural tradeoffLookup tables marked ext::napalm::root := 'reference' (such as BillingPlan or Role) and unrooted tables read by single-root policies (such as ext::auth::Identity) join locally on every shard. Writes commit atomically across every shard in lockstep so low-churn lookup tables join locally at read time. |
Cross-root analytics (core copy) | Consolidated read-only core shard | Architectural tradeoffInstead of scatter-gather fan-out that stalls on the slowest data shard, napalm core-copies add (POST /) streams every data shard’s commits onto one read-only shard. Cross-root reports run under access policies at the caller’s Napalm-Bookmark without adding load to primary shards. |
| Unpinned or multi-root writes | Refused before execution | Architectural tradeoffMutations touching multiple roots or unpinned root scans surface in napalm roots and are rejected on distributed branches so queries never hold cross-shard locks. |
Enabling placement and splitting shards online#
A project starts on one shard and opts into horizontal distribution explicitly. Audit root inference and deployed query routing first, backfill root mappings in place, attach a core copy when your app serves cross-root reads and split or attach data shards while live traffic continues.
Online shard splits
Online shard splits move half the buckets while your project URL stays unchanged.
Run the four commands below in sequence to inspect roots, enable placement, attach an optional core copy and split a busy shard.
# 1. Inspect inferred roots, movable links and per-query routing classesnapalm roots acme-app # 2. Record each row's root in bounded background batches on mainnapalm placement enable acme-app --wait # 3. Provision a consolidated core copy for cross-root reporting queriesnapalm core-copies add acme-app --wait # 4. Split a busy data shard in half onlinenapalm placement split acme-app --shard shard-0a1b2c3d4e --waitTo attach an empty pre-sized shard before moving chosen buckets, scale the cluster with napalm clusters scale <cluster> --data-shards 2 and run napalm placement add-shard acme-app --shard <name> --wait. Once every bucket and root override has moved off a non-base shard, detach that shard from the branch with napalm placement let-go acme-app --shard <name> --wait. Decommission an unneeded core copy with napalm core-copies remove acme-app --shard <name> --wait.
Isolating hot roots and live bookmark cutover#
When one root subtree (such as a busy project, world or enterprise organization) drives heavy write traffic, inspect top roots by read and write volume (GET /) or compute bucket rebalance recommendations (napalm placement rebalance / GET /). Move a numbered bucket or isolate a single root UUID onto a dedicated shard through POST /.
Root overrides
Root overrides move one busy root onto a dedicated shard online.
Check 24-hour shard balance first, then move a numbered bucket or isolate a single root UUID from the CLI.
# Check per-shard load share and suggested bucket moves over the past 24 hoursnapalm placement rebalance acme-app --hours 24 # Move an entire numbered bucket of roots to rebalance shard utilizationnapalm placement move acme-app --bucket 12 --shard shard-k3m9x2p7qa --wait # Isolate one high-traffic root UUID onto a dedicated shard via a root overridenapalm placement move acme-app --root 0192c3f4-6b1a-7d8e-9f00-1a2b3c4d5e6f --shard shard-k3m9x2p7qa --wait # Inspect active bucket ranges, root overrides and core copy statusnapalm placement show acme-appDuring napalm placement move and napalm placement split, Napalm copies existing rows and streams new commits to the destination shard in the background while the source shard continues serving. Reads never pause, and writes to the moving bucket or root pause for only a few seconds at the final map switch. On a distributed branch, Napalm-Bookmark carries a commit position per shard, so clients passing bookmarks opaquely preserve read-your-own-writes across replicas, core copies and live shard cutovers. Open live query subscriptions on a moved root re-evaluate automatically on the destination shard.
Regional root pinning and single-root restore#
Root overrides also enforce regional data residency and single-root point-in-time recovery on shared branches without provisioning separate projects per region or account.
Regional root pins
Regional pins move a root in-region and block moves outside that region.
Single-root restore
Single-root restores rewind one root subtree while neighboring roots keep serving.
Provision shard capacity in the target region first, then pin a root to that region or rewind a single root to an earlier timestamp.
# Split a shard into Frankfurt so the branch has capacity in that regionnapalm placement split acme-app --shard shard-0a1b2c3d4e --region fra --wait # Pin one root UUID to shards in Frankfurt (migrates the root if needed)napalm placement keep acme-app 0192c3f4-6b1a-7d8e-9f00-1a2b3c4d5e6f --region fra --wait # Rewind one root and all descendant rows without touching co-located rootsnapalm placement restore-root acme-app 0192c3f4-6b1a-7d8e-9f00-1a2b3c4d5e6f --to 2026-11-14T16:20:00Z --wait- Regional residency
napalm placement keep(POST /) migrates the root’s rows to a shard in the target region as a root override and blocks later rebalances or manual moves outside that region (projects/ {id}/ roots/ {root}/ region 400 outside_region). Pinning to a region where the branch holds no shard returns400 no_shard_in_region. Pass--anywhereto clear the pin.- Single-root rewind
napalm placement restore-root(POST /) rewinds one root UUID and every descendant record toprojects/ {id}/ root-restores targetTimefrom the shard’s backups while co-located roots keep serving reads and writes. Whole-shard restores (napalm branches restore) refuse distributed branches with409 branch_distributed.
Cluster shapes#
| Shape | Default topology |
|---|---|
solo | One machine running PostgreSQL and one engine. |
standard | A primary, a replica in another zone and two engines behind one endpoint. |
scale | The standard shape with as many engines and replicas as the traffic needs. |
Shape upgrades run online behind your existing URL. Moving from solo to standard adds a replica in a second availability zone. Once caught up, the replica acknowledges every commit before the primary returns.
Failover and high availability#
When a shard’s primary stops answering for 30 seconds, a replica takes over automatically. Requests follow the new primary right away. Once the failed server recovers, the former primary rejoins as a replica.
Automatic failover
A caught-up replica takes over writes when a primary stops answering.
Failover, planned switchovers and commit durability depend on your cluster shape and replica settings.
- Planned switchover
- Run
napalm clusters switchover <cluster>(or click Switch over in the console). The replica catches up to the last write and becomes the primary, and the old primary becomes a replica. A switchover loses no data. - Unplanned failover
- Napalm fails over automatically when a primary’s server is lost, and the new primary holds every acknowledged write. If no replica holds every acknowledged write, Napalm promotes a replica only when that replica trails the old primary by at most 16 MiB of changes.
- Synchronous commits
- On
standardandscaleclusters, a write returns only after a replica in the same region saves that write to disk. If all replicas become unreachable for over 5 seconds, the primary commits alone until a replica reconnects. - Refusing local commits
napalm clusters commit-without-replica <cluster> refuseturns local commits off. While a shard has no replica streaming, the shard’s writes wait and reads continue. A shard has no replica streaming when the only replica is lost, and after a failover until another member follows the new primary. With two replicas, a shard keeps accepting writes when one replica is lost.- Solo recovery
- A
solocluster has no replica. Restarting the machine recovers from the attached disk without data loss. If the machine stays unreachable past 10 minutes and backups are enabled, Napalm restores a replacement machine from encrypted backups and applies any newer commits from the change log.
Continuous backups#
Napalm archives every commit to encrypted object storage within 60 seconds. On clusters with a replica, nightly full backups add no load to the primary. Backups are encrypted with a per-cluster key and kept for 7 days by default (configurable to 7, 14, 30 or 90 days).
Queue an immediate on-demand backup with napalm clusters backup <cluster> or from the cluster page in the console.
Point-in-time restore#
Wind a branch back in place to any RFC 3339 timestamp inside the retention window. The branch keeps the same URL and TLS certificate, so applications reconnect as soon as the restore completes.
A restore rewinds the branch’s whole shard, so every other branch on the same shard goes back to the same moment. The command lists the affected branches before asking for confirmation. A branch created on the shard after the restore point blocks the restore until the branch is dropped. The console has the same restore under a project’s Branches.
On a branch spread across shards, napalm placement restore-root rewinds a single root subtree without touching any other root on the shard. Pass --with to napalm branches restore to name co-located branches in non-interactive scripts. Rollbacks and restores lists each refusal and picks the smallest fix for a bad release.
Maintenance holds#
Ahead of a launch, place a maintenance hold with napalm clusters hold <cluster> --reason "Launch week" --for 3d to defer Napalm’s automated maintenance on a cluster for up to a week. Nightly backups and certificate renewals wait during the hold while your org’s requests, automatic failover and continuous commit archiving keep running.
Chaos lab#
Every Napalm release and nightly build runs fault-injection campaigns against disposable clusters. Scenarios crash database servers while clients write, stop engines holding live streams, drop the network to replicas while revoking permissions and run isolated callers and roots side by side.
Automated fault campaigns
Nightly fault runs inject server and network failures against disposable clusters.
Incomplete evidence is recorded as Inconclusive rather than Passed, and every passing run verifies six invariants.
| Invariant | Verified condition |
|---|---|
| Durability | Every acknowledged write is intact after failover or recovery |
| Single writer | The old primary rejoins as a replica, and no replica takes over from a primary that still answers |
| Caller and root isolation | No answer, error or partial answer carries rows belonging to another caller or root |
| Policy enforcement | A revoked grant, sign-in or signing key reads nothing, even through a lagging replica |
| Reads after writes | Each read right after a write returns the write |
| Autonomous recovery | The cluster returns to full health without operator intervention |
Inspect recent fault runs and pass rates on the Chaos lab page.