Diffinery

homeflare/celldpublic

celld/README.md
263 lines · 11.2 KBRaw History
1# celld
2
3Self-hosted, distributed **Durable Objects**.
4
5celld is an open-source daemon that runs Cloudflare Workers and Durable
6Objects on your own machines. Each object is its own SQLite database.
7celld addresses an object by name and replicates it to a bucket that you
8own. The bucket can be S3-compatible, Google Cloud Storage, or Azure
9Blob Storage. The nodes coordinate through that bucket alone, with no
10control plane and no consensus. Because every object is its own small
11database, applications shard by construction — the contention and
12blast-radius failures of one shared database are designed out, not
13managed. A cell that no node holds is inactive, and an inactive cell
14costs nearly nothing. Learn more at
15[celld.dev](https://celld.dev) or read the
16[documentation](https://celld.dev/docs).
17
18## How it works
19
20Every `celld` node embeds V8 and executes Wrangler bundles. The fleet shares
21one bucket, which contains deployments, cell state, and small ownership
22records. The bucket can be S3-compatible, Google Cloud Storage, or Azure
23Blob Storage. Object-storage compare-and-swap ensures that exactly one
24node owns a cell at a time, without a membership protocol, failure
25detector, or consensus service.
26
27celld continuously replicates each cell's SQLite database to the bucket.
28When a cell moves, or when an inactive cell activates, its new owner restores
29that database and resumes execution. The bucket is the durable source of
30truth; nodes are replaceable.
31
32## Install
33
34The installer downloads the `celld` binary (provenance is verifiable with
35`gh attestation verify`):
36
37```sh
38curl -fsSL https://celld.dev/install.sh | sh
39```
40
41Put `~/.local/bin` on your `PATH` if the installer asks you to.
42
43Worker projects deployed with `celld deploy` need
44[esbuild](https://esbuild.github.io) on `PATH`; asset-only projects do not.
45
46The installer keeps each release under `~/.local/lib/celld/releases` and points
47one symlink at the current one. To remove celld, delete the symlink and the
48releases:
49
50```sh
51rm `which celld` && rm -rf ~/.local/lib/celld
52```
53
54## Container
55
56The release image contains the `celld` binary and is published for Linux
57x86-64 and ARM64:
58
59```sh
60docker run --rm ghcr.io/denoland/celld --version
61```
62
63Persist the runtime's local state and pass the standard AWS credential
64environment through:
65
66```sh
67docker volume create celld-state
68docker run --rm --network host \
69 -e AWS_ACCESS_KEY_ID \
70 -e AWS_SECRET_ACCESS_KEY \
71 -e AWS_SESSION_TOKEN \
72 -e CELLD_WATCH=/var/lib/celld/state \
73 -v celld-state:/var/lib/celld \
74 ghcr.io/denoland/celld \
75 --bucket s3://my-cells-bucket \
76 --endpoint https://ACCOUNT.r2.cloudflarestorage.com \
77 --region auto \
78 --listen 0.0.0.0:8080 \
79 --internal-listen 10.0.0.12:8081 \
80 --advertise node-a.internal:8081
81```
82
83Drop `--endpoint` and `--region` for AWS S3. Expose port 8080 through the load
84balancer, and keep port 8081 on the private network.
85
86## Run it
87
88celld uses the standard AWS credential chain. Deploy to an S3-compatible
89bucket, then start celld against the same bucket:
90
91```sh
92celld deploy . \
93 --bucket s3://my-cells-bucket
94
95celld \
96 --bucket s3://my-cells-bucket \
97 --listen 0.0.0.0:8080 \
98 --internal-listen 10.0.0.12:8081 \
99 --advertise 10.0.0.12:8081
100```
101
102Use `--endpoint` for another S3-compatible service and `--region` when it
103cannot be inferred. A `gs://` bucket selects Google Cloud Storage. celld then
104uses the Cloud Storage XML API with generation preconditions. Authentication
105uses Application Default Credentials. celld rejects an S3 `--endpoint` for a
106`gs://` bucket, and it ignores the storage region:
107
108```sh
109celld deploy . --bucket gs://my-cells-bucket
110celld --bucket gs://my-cells-bucket --listen 0.0.0.0:8080 \
111 --internal-listen 10.0.0.12:8081 --advertise 10.0.0.12:8081
112```
113
114An `az://` bucket selects Azure Blob Storage, where the NAME is the
115container. The storage account comes from `AZURE_STORAGE_ACCOUNT_NAME`.
116celld requires exactly one storage account key, managed identity, or workload
117identity. An AKS workload identity uses `AZURE_AUTHORITY_HOST`,
118`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_FEDERATED_TOKEN_FILE`.
119The authority host must identify the public Azure cloud. A Microsoft Entra
120identity needs data-plane permission to read, write, list, and delete blobs.
121The `Storage Blob Data Contributor` role supplies these permissions. celld
122rejects an S3 `--endpoint` for an `az://` bucket, and it ignores the storage
123region. celld qualifies an `az://` bucket: the conditional-write contract and
124the multipart upload path were tested against a live Azure account on
1252026-08-18, under each of the three credential families named above. See
126[ownership and fencing](docs/fencing.md):
127
128```sh
129export AZURE_STORAGE_ACCOUNT_NAME=myaccount
130celld deploy . --bucket az://my-cells-container
131celld --bucket az://my-cells-container --listen 0.0.0.0:8080 \
132 --internal-listen 10.0.0.12:8081 --advertise 10.0.0.12:8081
133```
134
135A fleet runs one application, and every node loads its
136latest successfully committed deployment from `deploy/current.json`. Run
137`celld --help` for the complete command line.
138Deployment objects use the documented types in `crates/celld/protocol.rs`. `celld
139deploy` invokes `esbuild` from `PATH` for Worker code, accepts the supported
140Wrangler config subset—including co-deployed or asset-only static
141assets—and writes those objects directly. Every node discovers owners and
142peers from bucket leases; there is no account or join service.
143
144Peer HTTP and the operator API use the internal listener. Put every advertised
145address on a trusted private network or an encrypted overlay such as WireGuard
146or Tailscale. Do not publish the internal port. celld rejects a literal public
147IP unless you supply `--unsafe-public-advertise`. An explicit advertised
148address requires an explicit internal-listener address. celld cannot verify a
149hostname or a translated port, so you must route the advertised address to the
150internal listener. The first current node creates `fleet/peer-auth.json` in the
151bucket. All peer requests are
152protocol-versioned, body-bound, HMAC-authenticated, clock-bounded, and
153replay-protected with that fleet secret. Treat access to the bucket and its
154credentials as fleet administrator access.
155
156## Operate a fleet
157
158`celld diagnose` enumerates every node lease by default, then performs a signed
159direct probe of each live peer:
160
161```sh
162celld diagnose --bucket s3://my-cells-bucket
163```
164
165The report keeps checking after an individual failure and distinguishes
166expired records, malformed or unsafe advertise addresses, unreachable peers,
167and incompatible protocols. It also prints each node's coarse resident-cell,
168WebSocket, RSS, CPU, file-descriptor, pressure, and shedding sample. Pass one
169or more `--peer NODE_ID` options to restrict the check.
170
171`celld d1` runs SQL and migrations against a deployed D1 database. It finds a
172node through the same node leases, and that node sends the work to the node
173that owns the database:
174
175```sh
176celld d1 migrations apply ledger --bucket s3://my-cells-bucket
177```
178
179Set a hard resident-cell limit on each loaded node:
180
181```sh
182CELLD_MAX_RESIDENT_CELLS=1000 \
183celld --bucket s3://my-cells-bucket --listen 0.0.0.0:8080 \
184 --internal-listen 10.0.0.12:8081 --advertise node-a.internal:8081
185```
186
187celld enables a memory threshold at 80% of the available memory by default. Set
188`CELLD_MAX_RSS_MB` to change the threshold, or set it to `0` to disable memory
189pressure shedding. celld measures the memory that the cells hold, and not the
190resident set size of the process. The two differ, because the memory allocator
191keeps some freed pages instead of returning them to the operating system.
192Shedding a cell cannot return those pages, so a threshold on the resident set
193size holds a node in pressure after the node gives every cell back. The `/state`
194route reports both numbers.
195
196celld also applies an absolute cap to the resident set size of the process. The
197cap is 95% of the available memory. It protects the node when the allocator
198holds memory that shedding cannot return, because the operating system stops a
199process that uses more memory than the machine has. The node logs a warning when
200this cap applies.
201
202The cap is a share of the machine, and celld does not derive it from the
203threshold. A `CELLD_MAX_RSS_MB` at or above 95% of the available memory therefore reaches
204the cap. The cap is then the effective limit. The node decides on its resident
205set size, and celld reports this at startup. `CELLD_MAX_RSS_MB=0`
206disables the threshold and the cap together. When celld cannot read the size of
207the available memory, it applies a cap of 125% of an explicit threshold.
208
209Each isolate also has a V8 heap limit, and this limit is separate from the
210memory of the node. The default is 128 MB, and it matches the limit of a
211Durable Object on Cloudflare. Set `CELLD_V8_HEAP_LIMIT_MB` to change it. The
212limit decides how much state one isolate can hold, so it decides how many
213hibernatable WebSocket clients a cell can carry. Each client holds state in the
214heap. A cell holds approximately 50,000 clients with the default limit, and it
215needs approximately 512 MB to hold 100,000 clients.
216
217An isolate that uses more than 90% of this limit refuses a new hibernatable
218WebSocket, and the error names the heap. The refusal is not permanent, and the
219isolate accepts a WebSocket again when the use of the heap falls under 90%.
220
221An isolate that reaches the limit stops more than an accept. It also stops the
222materialization of a SQL result set, and that error names the heap too. celld
223measures the heap before each event, and the isolate serves again when the use
224of the heap falls under 75% of the limit. An idle isolate holds a dead heap
225until something allocates again, so celld forces a collection when a
226measurement is above that share. A restart of the process is not necessary.
227
228Under pressure, celld durably replicates and fences the least-recently used idle
229cells. It then publishes the cells as unowned without resetting their epochs.
230Those cells become inactive, and celld refuses to reacquire new unowned cells.
231
232Each limit releases separately. The threshold releases when the memory in use
233falls to 80% of the threshold. The cap releases when the resident set size falls
234to 80% of the cap. A crossing of one limit therefore does not hold the node
235against the other.
236
237A spare receives no assignment. It acquires a released cell through the same
238bucket protocol when normal traffic reaches it. celld does not shed a cell with
239active work or a live host WebSocket.
240
241## Contributions
242
243Pull requests are disabled. Coding agents make it too easy to send a large,
244low-context change that costs maintainers more time than it saves. Thoughtful
245contributions are welcome; please understand the code, keep the patch focused,
246and respect the review time you are asking for.
247
248Send a `git format-patch` attachment to [[email protected]](mailto:[email protected]).
249
250Contributor License Agreement: By emailing a patch, you certify that you have
251the right to submit it and assign to Deno Land Inc. all rights in the patch
252that you can assign. Where a right cannot be assigned, you grant Deno Land
253Inc. a perpetual, irrevocable,
254worldwide, royalty-free, transferable, sublicensable license to use, modify,
255combine, relicense, redistribute, or publish the patch, in whole or in part,
256with or without attribution.
257
258## License
259
260[Apache-2.0](LICENSE)
261
262See the [limitations](docs/limitations.md) and
263[security](docs/security.md) pages before operating a public fleet.