| 1 | # What celld guarantees |
| 2 | |
| 3 | celld makes two promises about your data. Exactly one node serves a cell |
| 4 | at a time, so two machines never write the same database. And celld does |
| 5 | not answer a write until that write survives a failure, so nothing you |
| 6 | were told succeeded is lost. |
| 7 | |
| 8 | This page is how both promises are kept. Fencing is the part that keeps |
| 9 | the first one true when a node is slow, paused, or cut off from the |
| 10 | network: celld refuses that node's writes rather than trusting it to |
| 11 | notice it lost the cell. Both claims rest on the object |
| 12 | store, so this page starts with what you must provide: a bucket with |
| 13 | working conditional writes, and a supervisor that restarts the process. |
| 14 | The mechanism follows, so you can check the argument against the code. |
| 15 | |
| 16 | ## What the bucket must provide |
| 17 | |
| 18 | celld needs three properties from the object store: |
| 19 | |
| 20 | - A conditional create: the write must fail when the object exists. |
| 21 | - A conditional overwrite: the write must fail when the object changed |
| 22 | after the read. |
| 23 | - Read-after-write consistency: a read after a successful write must |
| 24 | return that write. |
| 25 | |
| 26 | The qualified stores are Amazon S3, Cloudflare R2, Tigris, Google Cloud |
| 27 | Storage, and Azure Blob Storage. celld's release tests run against R2, |
| 28 | and the S3 path uses the same client and the same headers. |
| 29 | |
| 30 | Backblaze B2, Hetzner Object Storage, and DigitalOcean Spaces do not |
| 31 | implement the required conditional writes. celld is not correct on such |
| 32 | a store: two nodes can then own one cell. A store can also accept the |
| 33 | conditional headers and ignore the condition, and that store fails late |
| 34 | and silently — so run the storage test below. |
| 35 | |
| 36 | MinIO (the community edition) implements the conditional writes and |
| 37 | passes the storage test, but celld has not qualified it for production. |
| 38 | One release is broken: RELEASE.2025-09-06T17-38-46Z answers the |
| 39 | conditional create of an absent object with `NoSuchKey`, so the first |
| 40 | deploy fails (denoland/celld#162). Use RELEASE.2025-09-07T16-13-09Z or |
| 41 | later. |
| 42 | |
| 43 | The request dialect differs per provider. An S3-compatible bucket gets |
| 44 | the `If-None-Match: *` and `If-Match` headers, and the condition |
| 45 | compares the etag. A `gs://` bucket selects the Cloud Storage XML API |
| 46 | with the `x-goog-if-generation-match` precondition and OAuth |
| 47 | credentials, because Cloud Storage does not apply `If-Match` to a PUT. |
| 48 | An `az://` bucket (the NAME is the container) uses the same `If-` |
| 49 | headers, which Put Blob applies. The adapter treats `AlreadyExists` and |
| 50 | `Precondition` (HTTP 412 on Azure) as clean conditional-write |
| 51 | rejections and keeps every other error ambiguous, because an ambiguous |
| 52 | write can have changed the object. |
| 53 | |
| 54 | Azure was qualified on 2026-08-18 under an account key, a VM managed |
| 55 | identity, and an AKS workload identity, single-node. A managed identity |
| 56 | on Azure App Service or Azure Container Apps does not work; see |
| 57 | [limitations](limitations.md). |
| 58 | |
| 59 | ## The storage test |
| 60 | |
| 61 | No store publishes these properties, so celld asks the store directly. |
| 62 | The command `celld diagnose` sends four conditional writes to your |
| 63 | bucket and reports the result: |
| 64 | |
| 65 | ``` |
| 66 | ok bucket conditional write (create, reject-create, update, reject-stale) |
| 67 | ``` |
| 68 | |
| 69 | Two of the four writes must fail. A store that accepts either one |
| 70 | cannot fence a cell, so celld names the store as the fault and the |
| 71 | command exits with an error. Each node repeats the test once at |
| 72 | startup, and a node that finds a broken store stops. Set |
| 73 | `CELLD_STORAGE_PROBE=0` to disable the startup test, or run |
| 74 | `celld diagnose --read-only` with a credential that cannot write. |
| 75 | |
| 76 | The test writes and deletes one small object under `probe/`. A process |
| 77 | that stops mid-test can leave the object behind; it is small, and celld |
| 78 | never reads it. celld reserves `probe/` together with `cells/`, |
| 79 | `nodes/`, `node-cells/`, `fleet/`, `deploy/`, `deploy-blobs/`, `wake/`, |
| 80 | and `telemetry/`, and it deletes objects under some of them, so an |
| 81 | application must not write under any of these prefixes. |
| 82 | |
| 83 | celld does not require a ranged read today, so a store that ignores the |
| 84 | `Range` header can still run a fleet. |
| 85 | |
| 86 | ## The supervisor |
| 87 | |
| 88 | You must run celld under a supervisor that restarts the process, such |
| 89 | as systemd, Docker with a restart policy, or Kubernetes. A node fences |
| 90 | itself when it loses its lease (the mechanism is below), and a fenced |
| 91 | process exits; without a restart, the fleet loses that capacity until |
| 92 | an operator intervenes. |
| 93 | |
| 94 | The supervisor must restart without an attempt limit, and it must wait |
| 95 | at least one lease lifetime between attempts. A node that cannot |
| 96 | acquire a lease at startup retries and does not exit, so a repeated |
| 97 | fence needs a node that acquires a lease and then loses it, and the |
| 98 | wait keeps that cycle slow enough to observe. |
| 99 | |
| 100 | ## The mechanism |
| 101 | |
| 102 | The short version: the ownership records use conditional writes, so two |
| 103 | nodes cannot acquire one cell. The replicated data carries its fencing |
| 104 | epoch in the object key, so a node that lost ownership writes only into |
| 105 | a superseded prefix. And before celld acknowledges a write, it proves |
| 106 | the write durable and confirms that it still owns the cell. |
| 107 | |
| 108 | ### The ownership record |
| 109 | |
| 110 | Each cell has one ownership record in the bucket. The record names the |
| 111 | owner node's session and carries a fencing epoch. A node acquires a |
| 112 | cell with a conditional write — a create when no record exists, a |
| 113 | compare-and-swap on the previous record when one does — and the bucket |
| 114 | accepts one such write, so two nodes cannot acquire the same cell. |
| 115 | |
| 116 | Every activation advances the epoch, a takeover and a local wake alike. |
| 117 | Each owner therefore replicates under a fresh epoch, and an epoch never |
| 118 | has two writers. |
| 119 | |
| 120 | ### The epoch prefix |
| 121 | |
| 122 | The replicator copies each cell's SQLite data to the bucket under |
| 123 | `cells/<cell>/ltx/e<epoch>/`, with plain unconditional PUTs. The epoch |
| 124 | in the key is the fence: a node that lost ownership can keep writing, |
| 125 | but its writes land in a superseded prefix, and a restore selects the |
| 126 | current lineage. (The tiering path can first combine segments from many |
| 127 | cells into a node bundle, and it drains each segment into its per-cell |
| 128 | prefix later.) |
| 129 | |
| 130 | The prefix protects the new owner's data from stale writes. The next |
| 131 | two sections protect the durability promise. |
| 132 | |
| 133 | ### The acknowledgement rule (RPO=0) |
| 134 | |
| 135 | A gate holds each write response until a durability proof covers the |
| 136 | write. After a bucket proof, celld reads the ownership record once and |
| 137 | acknowledges only if the record still names this node at this epoch. A |
| 138 | partitioned node can commit locally and replicate into its superseded |
| 139 | prefix, but the ownership read then shows the new owner, so celld does |
| 140 | not acknowledge the write. The check reads the record instead of |
| 141 | comparing a clock, so a paused process or a skewed clock cannot pass |
| 142 | it. |
| 143 | |
| 144 | A fleet proof does not require this read. The owner sends each write to |
| 145 | one or two other nodes, which hold a copy of its recent writes; those |
| 146 | nodes are its followers, and the set of them is the ensemble. Every |
| 147 | follower must fsync the write, and a takeover seals the prior node-log |
| 148 | session before it restores, so the stale owner cannot complete another |
| 149 | fleet proof. |
| 150 | |
| 151 | ### The ensemble needs two nodes |
| 152 | |
| 153 | A node picks its followers from the other nodes in the fleet, so it never |
| 154 | counts itself. One follower is enough, therefore a fleet needs two |
| 155 | running celld nodes before any node can complete a fleet proof. |
| 156 | `CELLD_DURABILITY=fleet` is the default, so a fleet of one node requests the |
| 157 | fleet posture and does not get it. |
| 158 | |
| 159 | A node recruits up to two followers, so a fleet of three or more nodes holds |
| 160 | three copies of an acknowledged write. The ensemble keeps acknowledging while |
| 161 | one follower remains, therefore a fleet does not fall back to the bucket each |
| 162 | time it loses a follower. |
| 163 | |
| 164 | A node without an ensemble stays correct. It acknowledges each write on a |
| 165 | bucket proof instead, so celld still does not acknowledge a write before a |
| 166 | durability proof covers it. The cost is latency: the write waits for the object |
| 167 | store, and an object store round trip is much slower than a follower fsync. |
| 168 | |
| 169 | ### The takeover recovery gate |
| 170 | |
| 171 | The default fleet mode can acknowledge a write once the node-log |
| 172 | ensemble stores it; the bucket upload can complete later. Each process |
| 173 | session therefore creates a conditional node-log record before its |
| 174 | first fleet-durable acknowledgement. |
| 175 | |
| 176 | A cold activation checks the prior owner's log records before it reads |
| 177 | the bucket. An absent record proves that the session never acknowledged |
| 178 | past the bucket, and a sealed record proves that recovery completed. An |
| 179 | open or recovering record makes the activation run recovery: it fences |
| 180 | the record with a compare-and-swap, seals the reachable followers, |
| 181 | uploads their retained segments and bundles into the per-cell prefixes, |
| 182 | and then marks the record sealed. The activation cannot restore until |
| 183 | this sequence completes. |
| 184 | |
| 185 | ### Full-prefix restore |
| 186 | |
| 187 | A restore selects the newest epoch prefix that contains LTX data, and |
| 188 | it reads the full contiguous chain from transaction zero. celld no |
| 189 | longer writes an epoch seal object, and a legacy `e<epoch>.seal.json` |
| 190 | object does not limit the chain. |
| 191 | |
| 192 | A fenced node can append an unacknowledged tail to an older prefix, and |
| 193 | a later restore can expose that tail. This does not violate the |
| 194 | contract, because a failed or absent acknowledgement does not prove |
| 195 | that the write is absent. The rule reads the full chain because a |
| 196 | node-log recovery or a bundle drain can add an acknowledged tail after |
| 197 | an earlier restore; a restore that stopped at the earlier cut would |
| 198 | hide that tail and lose acknowledged data. |
| 199 | |
| 200 | ### Self-fencing |
| 201 | |
| 202 | Each node holds a lease in the bucket. The lease carries an expiry, and |
| 203 | the node renews it after one third of the lifetime (`CELLD_TTL_MS`, |
| 204 | default 10000 ms). A renewal that does not reach the bucket does not |
| 205 | fence the node, because the node retries while the published expiry has |
| 206 | not passed. |
| 207 | |
| 208 | A node that cannot reach the bucket cannot renew and cannot replicate, |
| 209 | so it must not own cells. When its published expiry passes, it fences |
| 210 | itself: it stops each active cell, and it fails every request that it |
| 211 | has not completed. A node whose lease record another writer replaced or |
| 212 | removed fences at once, because that record proves the authority moved. |
| 213 | |
| 214 | The fence writes nothing to the bucket. Each peer already reads the |
| 215 | lease as dead or replaced, so a peer can acquire the cells through the |
| 216 | ownership records. And a request is safe even before the fence runs, |
| 217 | because celld compares the current time against the published expiry |
| 218 | each time it routes a request. |
| 219 | |
| 220 | A fenced node logs a line that starts with `SELF-FENCE:` and stops with |
| 221 | the exit code 3. celld reports other internal failures with the same |
| 222 | prefix and code, so the line names the cause. The fenced state is |
| 223 | terminal: only a restart returns the node to the fleet, through the |
| 224 | same cold-activation path that a peer failure uses. |
| 225 | |
| 226 | The failure of a node is a normal input, not a recovery procedure; the |
| 227 | [testing page](testing.md) shows the kill tests that exercise this |
| 228 | path. |