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