Diffinery

homeflare/celldpublic

celld/README.md
191 lines · 7.5 KBRaw History
1# celld
2
3Self-hosted, distributed **Durable Objects**.
4
5celld is an open-source daemon that runs Cloudflare Workers and Durable Objects
6on your own machines — a distributed system you program like a database. Each
7object is its own SQLite database, addressed by name and replicated to an
8S3-compatible bucket you own; nodes coordinate through that bucket alone, with
9no control plane or consensus. Because every object is its own small database,
10applications shard by construction — the contention and blast-radius failures
11of one shared database are designed out, not managed. Idle cells hibernate to
12nearly nothing. Learn more at [celld.dev](https://celld.dev) or read the
13[documentation](https://celld.dev/docs).
14
15## How it works
16
17Every `celld` node embeds V8 and executes Wrangler bundles. The fleet shares an
18S3-compatible bucket containing deployments, cell state, and small ownership
19records. Object-storage compare-and-swap ensures that exactly one node owns a
20cell at a time, without a membership protocol, failure detector, or consensus
21service.
22
23Litestream continuously replicates each cell's SQLite database to the bucket.
24When a cell moves or wakes up, its new owner restores that database and resumes
25execution. The bucket is the durable source of truth; nodes are replaceable.
26
27## Install
28
29The installer downloads the `celld` binary (provenance is verifiable with
30`gh attestation verify`):
31
32```sh
33curl -fsSL https://celld.dev/install.sh | sh
34```
35
36Put `~/.local/bin` on your `PATH` if the installer asks you to.
37
38celld follows the Unix convention of using ordinary external tools from
39`PATH`: running a node needs [Litestream](https://litestream.io) (or set
40`LITESTREAM_BIN`), and Worker projects deployed with `celld deploy` need
41[esbuild](https://esbuild.github.io). Asset-only projects do not. The daemon
42verifies Litestream at startup and exits immediately if it is missing.
43
44The installer keeps verified releases under `~/.local/lib/celld/releases` and
45atomically switches one `current` pointer. To remove celld, use the guarded
46uninstaller:
47
48```sh
49curl -fsSL https://celld.dev/uninstall.sh | sh
50```
51
52## Container
53
54The release image includes `celld`, the pinned Litestream binary, and esbuild
55for `celld deploy`. It is published for Linux x86-64 and ARM64:
56
57```sh
58docker pull ghcr.io/denoland/celld:0.0.1
59docker run --rm ghcr.io/denoland/celld:0.0.1 --version
60```
61
62`latest` and the Cargo version are convenient mutable tags. Use
63`sha-<40-character-public-commit>` when the exact image must be immutable.
64Persist the runtime's local state and pass the standard AWS credential
65environment through:
66
67```sh
68docker volume create celld-state
69docker run --rm --network host \
70 -e AWS_ACCESS_KEY_ID \
71 -e AWS_SECRET_ACCESS_KEY \
72 -e AWS_SESSION_TOKEN \
73 -e CELLD_WATCH=/var/lib/celld/state \
74 -v celld-state:/var/lib/celld \
75 ghcr.io/denoland/celld:0.0.1 \
76 --bucket s3://my-cells-bucket \
77 --endpoint https://ACCOUNT.r2.cloudflarestorage.com \
78 --region auto \
79 --listen 0.0.0.0:8080 \
80 --advertise node-a.internal:8080
81```
82
83Drop `--endpoint`/`--region` for real AWS S3. Behind a load balancer,
84give each node a distinct `--advertise` its peers can reach.
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 --advertise 10.0.0.12:8080
99```
100
101Use `--endpoint` for another S3-compatible service and `--region` when it
102cannot be inferred. A fleet runs one application, and every node loads its
103latest successfully committed deployment from `deploy/current.json`. Run
104`celld --help` for the complete command line.
105Deployment objects use the documented types in `src/protocol.rs`. `celld
106deploy` invokes `esbuild` from `PATH` for Worker code, accepts the supported
107Wrangler config subset—including co-deployed or asset-only static
108assets—and writes those objects directly. Every node discovers owners and
109peers from bucket leases; there is no account or join service.
110
111Peer HTTP does not terminate TLS. Put every advertised address on a trusted
112private network or an encrypted overlay such as WireGuard or Tailscale; do not
113publish the peer port directly. A literal public IP is rejected unless
114`--unsafe-public-advertise` is supplied explicitly. The first current node creates
115`fleet/peer-auth.json` in the bucket. All peer requests are protocol-versioned,
116body-bound, HMAC-authenticated, clock-bounded, and replay-protected with that
117fleet secret. Treat access to the bucket and its credentials as fleet
118administrator access.
119
120## Operate a fleet
121
122`celld diagnose` enumerates every node lease by default, then performs a signed
123direct probe of each live peer:
124
125```sh
126celld diagnose --bucket s3://my-cells-bucket
127```
128
129The report keeps checking after an individual failure and distinguishes
130expired records, malformed or unsafe advertise addresses, unreachable peers,
131and incompatible protocols. It also prints each node's coarse resident-cell,
132WebSocket, RSS, CPU, file-descriptor, pressure, and shedding sample. Pass one
133or more `--peer NODE_ID` options to restrict the check.
134
135Pressure shedding is opt-in while the first release's safe defaults are being
136measured. Set a resident-cell high and low watermark on loaded nodes:
137
138```sh
139CELLD_MAX_RESIDENT_CELLS=1000 \
140CELLD_RESIDENT_LOW_WATER=800 \
141celld --bucket s3://my-cells-bucket --listen 0.0.0.0:8080 \
142 --advertise node-a.internal:8080
143```
144
145On Linux, `CELLD_MAX_RSS_MB` and `CELLD_MAX_CPU_PERCENT` add process-memory and
146CPU triggers; the resident-cell watermark is portable. Under pressure, celld
147durably replicates and fences least-recently used idle cells, publishes them as
148unowned without resetting their epoch, and refuses to reacquire new unowned
149cells until the low watermark is reached. A spare receives no assignment: it
150acquires released cells through the same bucket protocol when normal traffic
151reaches it. Cells with active work or live host WebSockets are not shed.
152
153## Build from source
154
155```sh
156cargo build --locked
157cargo test --locked
158cargo clippy --all-targets --locked -- -D warnings
159```
160
161The root package builds the `celld` runtime. Its versioned object-storage
162protocol lives in `src/protocol.rs`. Small Wrangler projects under `examples/`
163exercise the supported Worker and Durable Object surface.
164
165The runtime and compatibility surface are still evolving. Public tests cover
166the standalone engine smoke path; conformance against the Workers and Durable
167Objects reference behavior, and a deterministic simulation of the distributed
168protocol under fault injection, run before each release.
169
170## Contributions
171
172Pull requests are disabled. Coding agents make it too easy to send a large,
173low-context change that costs maintainers more time than it saves. Thoughtful
174contributions are welcome; please understand the code, keep the patch focused,
175and respect the review time you are asking for.
176
177Send a `git format-patch` attachment to [[email protected]](mailto:[email protected]).
178
179By emailing a patch, you certify that you have the right to submit it and assign
180to Deno Land Inc. all rights in the patch that you can assign. Where a right
181cannot be assigned, you grant Deno Land Inc. a perpetual, irrevocable,
182worldwide, royalty-free, transferable, sublicensable license to use, modify,
183combine, relicense, redistribute, or publish the patch, in whole or in part,
184with or without attribution.
185
186## License
187
188[MIT](LICENSE)
189
190See the [support matrix](docs/support.md), [v0.0.1 limitations](docs/limitations.md),
191and [security](docs/security.md) before operating a public fleet.