celld/README.md
| 1 | # celld |
| 2 | |
| 3 | Self-hosted, distributed **Durable Objects**. |
| 4 | |
| 5 | celld is an open-source daemon that runs Cloudflare Workers and Durable |
| 6 | Objects on your own machines. Each object is a cell: a named server with |
| 7 | its own SQLite database. celld stores the long-term state in a bucket |
| 8 | that you own — S3-compatible, Google Cloud Storage, or Azure Blob |
| 9 | Storage — and needs no serving control plane and no consensus service. |
| 10 | A cell that nothing is serving costs almost nothing. Learn more at |
| 11 | [celld.dev](https://celld.dev) or read the |
| 12 | [documentation](https://celld.dev/docs). |
| 13 | |
| 14 | ## How it works |
| 15 | |
| 16 | A node is one `celld` process, and you run one on each machine. Every |
| 17 | node embeds V8 and executes Wrangler bundles. The nodes that share one |
| 18 | bucket are a fleet, and that bucket holds the deployments, the cell |
| 19 | state, and small ownership records. A conditional bucket write gives a node the |
| 20 | ownership of a cell, so exactly one node owns a cell at a time — no |
| 21 | membership protocol, no failure detector, no consensus service. Signed |
| 22 | peer HTTP provides routing and replicated-log transport. |
| 23 | |
| 24 | celld captures each committed SQLite write as LTX data, the transaction |
| 25 | format the replication uses. A single node proves the write durable by |
| 26 | uploading that data to the bucket. A fleet of two or more nodes proves it |
| 27 | sooner: the owner sends the data to one or two other nodes, and the write |
| 28 | is durable as soon as they hold it on their disks. celld uploads the data |
| 29 | to the bucket afterwards. A single node has no other node to send to, so |
| 30 | each write waits for the bucket, and those writes are much slower. |
| 31 | Before a takeover restores a cell, celld recovers an open log from the |
| 32 | prior owner, so the bucket holds the long-term state and nodes stay |
| 33 | replaceable. See [what celld guarantees](docs/guarantees.md) for the |
| 34 | complete protocol. |
| 35 | |
| 36 | ## Install |
| 37 | |
| 38 | The installer downloads the `celld` binary (provenance is verifiable with |
| 39 | `gh attestation verify`): |
| 40 | |
| 41 | ```sh |
| 42 | curl -fsSL https://celld.dev/install.sh | sh |
| 43 | ``` |
| 44 | |
| 45 | Put `~/.local/bin` on your `PATH` if the installer asks you to. |
| 46 | |
| 47 | Worker projects deployed with `celld deploy` need |
| 48 | [esbuild](https://esbuild.github.io) on `PATH`; asset-only projects do not. |
| 49 | |
| 50 | The installer keeps each release under `~/.local/lib/celld/releases` and points |
| 51 | one symlink at the current one. To remove celld, delete the symlink and the |
| 52 | releases: |
| 53 | |
| 54 | ```sh |
| 55 | rm `which celld` && rm -rf ~/.local/lib/celld |
| 56 | ``` |
| 57 | |
| 58 | ## Container |
| 59 | |
| 60 | The release image contains the `celld` binary and is published for Linux |
| 61 | x86-64 and ARM64: |
| 62 | |
| 63 | ```sh |
| 64 | docker run --rm ghcr.io/denoland/celld --version |
| 65 | ``` |
| 66 | |
| 67 | Persist the runtime's local state and pass the standard AWS credential |
| 68 | environment through: |
| 69 | |
| 70 | ```sh |
| 71 | docker volume create celld-state |
| 72 | docker run --rm --network host \ |
| 73 | -e AWS_ACCESS_KEY_ID \ |
| 74 | -e AWS_SECRET_ACCESS_KEY \ |
| 75 | -e AWS_SESSION_TOKEN \ |
| 76 | -e CELLD_WATCH=/var/lib/celld/state \ |
| 77 | -v celld-state:/var/lib/celld \ |
| 78 | ghcr.io/denoland/celld \ |
| 79 | --bucket s3://my-cells-bucket \ |
| 80 | --endpoint https://ACCOUNT.r2.cloudflarestorage.com \ |
| 81 | --region auto \ |
| 82 | --listen 0.0.0.0:8080 \ |
| 83 | --internal-listen 10.0.0.12:8081 \ |
| 84 | --advertise node-a.internal:8081 |
| 85 | ``` |
| 86 | |
| 87 | Drop `--endpoint` and `--region` for AWS S3. Expose port 8080 through the load |
| 88 | balancer, and keep port 8081 on the private network. |
| 89 | |
| 90 | ## Run it |
| 91 | |
| 92 | Run an application locally without a cloud bucket: |
| 93 | |
| 94 | ```sh |
| 95 | celld dev |
| 96 | ``` |
| 97 | |
| 98 | The command starts one celld node and uses a local object store. It does not |
| 99 | require Docker or a cloud bucket. The Worker listener uses |
| 100 | `http://127.0.0.1:9876`. Use `celld dev --port PORT` to select a different |
| 101 | Worker port. Use `celld dev --host IP` to select a different interface. A |
| 102 | non-loopback IP exposes the Worker listener to the network, and the internal |
| 103 | operator listener stays on loopback. The command keeps the application state |
| 104 | in `.celld/dev`, so a later invocation uses the same durable data. |
| 105 | |
| 106 | The default display highlights the application URL and hides the node |
| 107 | warning and information logs. Use `celld dev --logs` to show these logs. |
| 108 | The errors remain visible without this flag. Set `NO_COLOR` to disable color, |
| 109 | or set `FORCE_COLOR` to enable color when the output is not a terminal. |
| 110 | `NO_COLOR` always takes priority. |
| 111 | |
| 112 | The command watches the project and rebuilds the application after a |
| 113 | source or configuration change. It keeps the current application running |
| 114 | if a build fails, and a successful restart retains the durable state. See |
| 115 | the [documentation](docs/README.md#develop-an-application-locally) for |
| 116 | the complete local-development contract. |
| 117 | |
| 118 | celld uses the standard AWS credential chain. On Amazon EKS, celld reads the |
| 119 | Pod Identity credentials from the injected environment variables and the |
| 120 | authorization-token file. Deploy to an S3-compatible bucket, then start celld |
| 121 | against the same bucket: |
| 122 | |
| 123 | ```sh |
| 124 | celld deploy . \ |
| 125 | --bucket s3://my-cells-bucket |
| 126 | |
| 127 | celld \ |
| 128 | --bucket s3://my-cells-bucket \ |
| 129 | --listen 0.0.0.0:8080 \ |
| 130 | --internal-listen 10.0.0.12:8081 \ |
| 131 | --advertise 10.0.0.12:8081 |
| 132 | ``` |
| 133 | |
| 134 | One node proves each write through the bucket, so a write costs one storage |
| 135 | round trip. Start a second node against the same bucket, and celld sends each |
| 136 | write to it: the write then finishes as soon as the second node holds the data |
| 137 | on its disk, which is much faster than the round trip. |
| 138 | |
| 139 | Run two or more nodes if write latency matters to you. The second node needs |
| 140 | no extra configuration, because a node finds the other nodes through the |
| 141 | bucket. |
| 142 | |
| 143 | How much faster depends on how far your bucket is and how loaded the fleet |
| 144 | is. A write to a region-local store takes about 90 ms. One loaded lab fleet |
| 145 | measured about 600 ms against a store that was not region-local, and about |
| 146 | 25 ms once a second node held the write. See |
| 147 | [what celld guarantees](docs/guarantees.md#the-ensemble-needs-two-nodes). |
| 148 | |
| 149 | Use `--endpoint` for another S3-compatible service and `--region` when it |
| 150 | cannot be inferred. A `gs://` bucket selects Google Cloud Storage: celld then |
| 151 | uses the Cloud Storage XML API with generation preconditions and |
| 152 | authenticates with Application Default Credentials. celld rejects an S3 |
| 153 | `--endpoint` for a `gs://` bucket, and it ignores the storage region: |
| 154 | |
| 155 | ```sh |
| 156 | celld deploy . --bucket gs://my-cells-bucket |
| 157 | celld --bucket gs://my-cells-bucket --listen 0.0.0.0:8080 \ |
| 158 | --internal-listen 10.0.0.12:8081 --advertise 10.0.0.12:8081 |
| 159 | ``` |
| 160 | |
| 161 | An `az://` bucket selects Azure Blob Storage, where the NAME is the |
| 162 | container and `AZURE_STORAGE_ACCOUNT_NAME` names the storage account. |
| 163 | celld requires exactly one credential family: a storage account key, a |
| 164 | managed identity, or a workload identity. An AKS workload identity uses |
| 165 | `AZURE_AUTHORITY_HOST`, `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and |
| 166 | `AZURE_FEDERATED_TOKEN_FILE`, and the authority host must identify the |
| 167 | public Azure cloud. A Microsoft Entra identity needs data-plane permission |
| 168 | to read, write, list, and delete blobs; the `Storage Blob Data Contributor` |
| 169 | role supplies these. celld rejects an S3 `--endpoint` for an `az://` bucket, |
| 170 | and it ignores the storage region. See |
| 171 | [what celld guarantees](docs/guarantees.md) for the qualification: |
| 172 | |
| 173 | ```sh |
| 174 | export AZURE_STORAGE_ACCOUNT_NAME=myaccount |
| 175 | celld deploy . --bucket az://my-cells-container |
| 176 | celld --bucket az://my-cells-container --listen 0.0.0.0:8080 \ |
| 177 | --internal-listen 10.0.0.12:8081 --advertise 10.0.0.12:8081 |
| 178 | ``` |
| 179 | |
| 180 | A fleet runs one application, and every node loads its latest successfully |
| 181 | committed deployment from `deploy/current.json`. `celld deploy` invokes |
| 182 | `esbuild` from `PATH` for Worker code, accepts the supported Wrangler config |
| 183 | subset — including co-deployed or asset-only static assets — and writes the |
| 184 | deployment objects directly, using the documented types in |
| 185 | `crates/celld/protocol.rs`. Every node discovers owners and peers from |
| 186 | bucket leases; there is no account or join service. Run `celld --help` for |
| 187 | the complete command line. |
| 188 | |
| 189 | Peer HTTP and the operator API use the internal listener. Put every |
| 190 | advertised address on a trusted private network or an encrypted overlay such |
| 191 | as WireGuard or Tailscale, and do not publish the internal port. celld |
| 192 | rejects a literal public IP unless you supply `--unsafe-public-advertise`. |
| 193 | An explicit advertised address requires an explicit internal-listener |
| 194 | address, and you must route the advertised address to the internal |
| 195 | listener — celld cannot verify a hostname or a translated port. The first |
| 196 | current node creates `fleet/peer-auth.json` in the bucket. Cell fetch and RPC |
| 197 | requests carry a protocol version and depend on the trusted private network. |
| 198 | Peer-control and reserved-cell operator requests use the fleet HMAC. This HMAC |
| 199 | binds each body and supplies a clock limit and replay protection. Treat access |
| 200 | to the bucket and its credentials as fleet administrator access. |
| 201 | |
| 202 | ## Operate a fleet |
| 203 | |
| 204 | `celld diagnose` enumerates every node lease by default, then performs a signed |
| 205 | direct probe of each live peer: |
| 206 | |
| 207 | ```sh |
| 208 | celld diagnose --bucket s3://my-cells-bucket |
| 209 | ``` |
| 210 | |
| 211 | The report keeps checking after an individual failure and distinguishes |
| 212 | expired records, malformed or unsafe advertise addresses, unreachable peers, |
| 213 | and incompatible protocols. It also prints each node's coarse resident-cell, |
| 214 | WebSocket, RSS, CPU, file-descriptor, pressure, and shedding sample. Pass one |
| 215 | or more `--peer NODE_ID` options to restrict the check. |
| 216 | |
| 217 | `celld cell list` lists the Durable Object instances in the fleet bucket: |
| 218 | |
| 219 | ```sh |
| 220 | celld cell list --bucket s3://my-cells-bucket |
| 221 | ``` |
| 222 | |
| 223 | The command prints one `Class:ID` cell scope per line. Give a class name to |
| 224 | list only the instances of that class, and pass `--json` for one JSON object |
| 225 | per line. An instance appears after the first event reaches it, because its |
| 226 | owner then writes an ownership record to the bucket. An ID that an application |
| 227 | only derives does not appear. |
| 228 | |
| 229 | The listing is bounded. One storage request returns at most 1000 instances, |
| 230 | so the command prints at most 1000 and reports on stderr that more exist. |
| 231 | Pass `--after SCOPE` to continue from the last instance printed, or `--all` |
| 232 | to read the whole listing. |
| 233 | |
| 234 | `celld d1` runs SQL and migrations against a deployed D1 database. It finds a |
| 235 | node through the same node leases, and that node sends the work to the node |
| 236 | that owns the database: |
| 237 | |
| 238 | ```sh |
| 239 | celld d1 migrations apply ledger --bucket s3://my-cells-bucket |
| 240 | ``` |
| 241 | |
| 242 | `celld kv` reads and writes a deployed KV namespace. Its bulk commands use the |
| 243 | Wrangler file format, so a Wrangler export can migrate directly into celld: |
| 244 | |
| 245 | ```sh |
| 246 | celld kv bulk put sessions wrangler-export.json \ |
| 247 | --bucket s3://my-cells-bucket |
| 248 | ``` |
| 249 | |
| 250 | `celld queue` inspects and controls a deployed Queue. A queue can continue to |
| 251 | accept messages while delivery is paused: |
| 252 | |
| 253 | ```sh |
| 254 | celld queue info jobs --bucket s3://my-cells-bucket |
| 255 | celld queue pause jobs --bucket s3://my-cells-bucket |
| 256 | celld queue resume jobs --bucket s3://my-cells-bucket |
| 257 | ``` |
| 258 | |
| 259 | Set a hard resident-cell limit on each loaded node: |
| 260 | |
| 261 | ```sh |
| 262 | CELLD_MAX_RESIDENT_CELLS=1000 \ |
| 263 | celld --bucket s3://my-cells-bucket --listen 0.0.0.0:8080 \ |
| 264 | --internal-listen 10.0.0.12:8081 --advertise node-a.internal:8081 |
| 265 | ``` |
| 266 | |
| 267 | celld enables a memory-pressure threshold at 80% of the available memory by |
| 268 | default. Set `CELLD_MAX_RSS_MB` to change the threshold, or set it to `0` to |
| 269 | disable memory-pressure shedding. In a Linux cgroup, the threshold uses the |
| 270 | greater of the allocator-adjusted RSS and the active cgroup working set. celld |
| 271 | calculates the working set as `memory.current` less `inactive_file` from |
| 272 | `memory.stat`, then it removes the measured allocator slack. This calculation |
| 273 | includes active kernel charges that process RSS does not report, and it excludes |
| 274 | file pages and allocator pages that celld cannot return by shedding a cell. The |
| 275 | `/state` route reports all four input measurements. |
| 276 | |
| 277 | A separate absolute cap applies to the complete cgroup charge at 95% of the |
| 278 | available memory. celld uses the process RSS when it cannot read a cgroup |
| 279 | charge. The cap protects the node when shedding cannot return a kernel charge. |
| 280 | The node logs a warning when the cap applies. The cap is a share of the |
| 281 | available memory, not a share of the threshold. Therefore, a |
| 282 | `CELLD_MAX_RSS_MB` value at or above 95% makes the cap the effective limit, and |
| 283 | celld reports the decision at startup. |
| 284 | `CELLD_MAX_RSS_MB=0` disables the threshold and the cap together. When celld |
| 285 | cannot read the size of the available memory, it applies a cap of 125% of an |
| 286 | explicit threshold. |
| 287 | |
| 288 | Under pressure, celld durably replicates and fences the least-recently used |
| 289 | idle cells, publishes them as unowned without resetting their epochs, and |
| 290 | refuses to reacquire new unowned cells. It does not shed a cell with active |
| 291 | work or a live host WebSocket. A spare node receives no assignment; it |
| 292 | acquires a released cell through the same bucket protocol when normal |
| 293 | traffic reaches it. Each limit releases separately. The threshold releases at |
| 294 | 80% of its value, and the cap releases at 80% of its value. Therefore, a |
| 295 | crossing of one limit does not hold the node against the other. |
| 296 | |
| 297 | Each isolate also has a V8 heap limit, separate from the memory of the node. |
| 298 | The default is 128 MB, and it matches the limit of a Durable Object on |
| 299 | Cloudflare; set `CELLD_V8_HEAP_LIMIT_MB` to change it. Each hibernatable |
| 300 | WebSocket client holds state in the heap, so the limit decides how many |
| 301 | clients a cell can carry: approximately 50,000 at the default, and |
| 302 | approximately 512 MB for 100,000. |
| 303 | |
| 304 | An isolate above 90% of this limit refuses a new hibernatable WebSocket, and |
| 305 | it accepts again when the use of the heap falls under 90%. An isolate that |
| 306 | reaches the limit also stops the materialization of a SQL result set; both |
| 307 | errors name the heap. celld measures the heap before each event, and the |
| 308 | isolate serves again when the use falls under 75% of the limit. An idle |
| 309 | isolate holds a dead heap until something allocates, so celld forces a |
| 310 | collection when a measurement is above that share. A restart of the process |
| 311 | is not necessary. |
| 312 | |
| 313 | ## Contributions |
| 314 | |
| 315 | Pull requests are disabled. Coding agents make it too easy to send a large, |
| 316 | low-context change that costs maintainers more time than it saves. Thoughtful |
| 317 | contributions are welcome; please understand the code, keep the patch focused, |
| 318 | and respect the review time you are asking for. |
| 319 | |
| 320 | Send a `git format-patch` attachment to [[email protected]](mailto:[email protected]). |
| 321 | |
| 322 | Contributor License Agreement: By emailing a patch, you certify that you have |
| 323 | the right to submit it and assign to Deno Land Inc. all rights in the patch |
| 324 | that you can assign. Where a right cannot be assigned, you grant Deno Land |
| 325 | Inc. a perpetual, irrevocable, worldwide, royalty-free, transferable, |
| 326 | sublicensable license to use, modify, combine, relicense, redistribute, or |
| 327 | publish the patch, in whole or in part, with or without attribution. |
| 328 | |
| 329 | ## License |
| 330 | |
| 331 | [Apache-2.0](LICENSE) |
| 332 | |
| 333 | See the [limitations](docs/limitations.md) and |
| 334 | [security](docs/security.md) pages before operating a public fleet. |