Diffinery

homeflare/celldpublic

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