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
- Add Napalm engines to scale connections, compilation, live streams and caching.
- Replicas
- Serve read queries and stand ready in another zone to take over writes.
- Horizontal shards
- Partition tenant roots across multiple primaries when writes or 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. Napalm places each tenant’s object graph on one shard by root without composite primary keys or manual tenant_id columns, routes single-root queries straight to the owning shard and rebalances buckets or individual roots 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 noisy-neighbor enterprise tenant 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 customer primaries.
Single-root shard routing
Stateless engines route single-root statements over the internal cluster backplane straight to the owning shard with zero cross-shard fan-out.
Replica & core-copy streaming
Data shards stream commits continuously to in-region read replicas and consolidated analytical core copies caught up to Napalm-Bookmark.
| 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, trading write latency for fast local joins on low-churn tables. |
Cross-tenant analytics (core copy) | Consolidated read-only core shard | Architectural tradeoffInstead of scatter-gather fan-out that stalls on the slowest customer 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 customer 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, avoiding distributed locks across customer shards. |
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-tenant reads and split or attach data shards while live traffic continues.
Online shard bucket split
Splitting a busy shard streams half of its numbered bucket range onto a new shard in the background while reads continue, then flips the placement map behind the same URL.
# 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-tenant 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 noisy tenants and live bookmark cutover#
When one enterprise tenant 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 override & live bookmark cutover
napalm placement move --root <uuid> streams existing rows and ongoing commits onto a dedicated shard, pausing writes for seconds at the final map switch while Napalm-Bookmark preserves read-your-own-writes.
# 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 noisy-neighbor 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 per-tenant point-in-time restore#
Root overrides also enforce regional data residency and single-tenant disaster recovery on shared multi-tenant branches without provisioning separate projects per customer.
Regional root pinning
napalm placement keep migrates one customer root to a target region (fra, iad) and blocks later moves outside that region with 400 outside_region.
Single-root point-in-time rewind
napalm placement restore-root rewinds one root UUID and every descendant record from shard backups while co-located tenants keep serving.
# 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 customer 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 tenant root and all descendant rows without touching co-located tenantsnapalm 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 tenants 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 the replica catches up, every commit waits for it to acknowledge.
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 promotion & single-writer guarantee
When a primary stops answering, a caught-up replica promotes behind the unchanged project URL while any recovering former primary rejoins strictly as a replica.
- 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 it 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 it 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 tenant root without touching any other tenant on the shard. Pass --with 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 tenants side by side. Incomplete evidence is recorded as Inconclusive, never Passed, and every passing run verifies six invariants.
Continuous fault-injection verification
Nightly campaigns crash primaries mid-write, sever replica links during permission revocation and drop engines holding live streams, marking any incomplete run Inconclusive rather than Passed.
| 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 |
| Tenant isolation | No answer, error or partial answer carries another tenant’s rows |
| 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.