Diffinery

homeflare/celldpublic

celld/docs/README.md
186 lines · 7.4 KBRaw History
1# celld documentation
2
3celld is a stateful distributed system. It runs server-side JavaScript on
4your machines and keeps all shared data in an S3-compatible bucket that
5you own. The JavaScript API is the same API that Cloudflare Workers and
6Durable Objects supply.
7
8In Cloudflare terms, a cell is a Durable Object: a small server with a
9name and a private SQLite database. You make one cell for each user, each
10document, each chat room, or each AI agent. A cell serves HTTP, holds
11WebSocket connections, sets alarms, and makes outbound connections. Each
12cell runs on one thread, so two requests to the same cell never run at
13the same instant. A second request can interleave only while the first
14awaits, and storage operations are synchronous, so a storage operation
15never interleaves at all. The data in a cell therefore stays consistent.
16Cells share no database, and the application divides into cells from the
17start.
18
19An idle cell hibernates to the bucket, where it is only an object in S3
20and costs almost zero. A resident cell is in memory. One 8 GB node holds
211,000 resident cells, so one resident cell costs approximately $0.05 each
22month.
23
24The bucket is the coordinator. There is no membership protocol, no
25failure detector, and no consensus service. One atomic write to the
26bucket gives a node the ownership of a cell. Replication sends the SQLite
27data of each cell to the bucket, and celld does not acknowledge a write
28before the data is there (RPO=0). The loss of a node therefore cannot
29lose an acknowledged write. To add a node to the fleet, point the node at
30the bucket.
31
32## Contents
33
34- [Install](#install)
35- [Configure object storage](#configure-object-storage)
36- [Deploy an application](#deploy-an-application)
37- [Start a node](#start-a-node)
38- [Add nodes](#add-nodes)
39- [Diagnose a fleet](#diagnose-a-fleet)
40- [Environment variables](#environment-variables)
41- [Cloudflare compatibility](cloudflare-compat.md)
42- [limitations](limitations.md)
43- [Security](security.md)
44- [Testing](testing.md)
45
46## Install
47
48The installer downloads the `celld` binary. Replication occurs in the
49celld process. A node does not need an external replicator. If your
50project contains Worker code, `celld deploy` needs esbuild. An asset-only
51project does not need esbuild.
52
53```sh
54curl -fsSL https://celld.dev/install.sh | sh
55```
56
57If the installer tells you, add `~/.local/bin` to `PATH`. To install one
58exact release, set `CELLD_VERSION` to the tag of that release, for example
59`v0.0.1`. To go back to a previous release, run the installer again with
60the tag of that release. The releases are on
61[GitHub](https://github.com/denoland/celld/releases). Each release has a
62GitHub Actions build attestation. To make sure that a downloaded file is
63correct, run `gh attestation verify <asset> --repo denoland/celld`.
64
65## Configure object storage
66
67celld uses the standard AWS credential chain. For Cloudflare R2, do these
68steps. Create a bucket. Create an S3 API token that has access to that
69bucket. Then set these variables:
70
71```sh
72export AWS_ACCESS_KEY_ID=...
73export AWS_SECRET_ACCESS_KEY=...
74export AWS_REGION=auto
75export S3_ENDPOINT=https://ACCOUNT_ID.r2.cloudflarestorage.com
76export CELLD_BUCKET=s3://YOUR-BUCKET
77```
78
79The bucket credentials give full control of the fleet. Keep them safe. The
80bucket contains the deployments, the SQLite replicas, the ownership
81records, the node leases, and the peer-authentication secret.
82
83## Deploy an application
84
85If the project contains Worker code, install `esbuild` on `PATH`. Then run
86`celld deploy` from an applicable Wrangler project:
87
88```sh
89git clone https://github.com/denoland/celld
90cd celld/examples/counter
91celld deploy . \
92 --bucket "$CELLD_BUCKET" \
93 --endpoint "$S3_ENDPOINT" \
94 --region "$AWS_REGION"
95```
96
97`celld deploy` accepts module Workers, Durable Object bindings, and static
98assets. An asset project can include a Worker or be asset-only. The asset
99functions include the assets binding, HTML handling, not-found handling,
100worker-first routes, `_headers`, and `_redirects`. If the Wrangler
101configuration contains an unknown key, the deploy stops with an error. See
102the [limitations](limitations.md) for the current deployment boundary.
103
104## Start a node
105
106For local development, the default listener is sufficient:
107
108```sh
109celld \
110 --bucket "$CELLD_BUCKET" \
111 --endpoint "$S3_ENDPOINT" \
112 --region "$AWS_REGION"
113```
114
115For a fleet node, bind the service. Advertise an address that the other
116nodes and the ingress can reach:
117
118```sh
119celld \
120 --bucket "$CELLD_BUCKET" \
121 --endpoint "$S3_ENDPOINT" \
122 --region "$AWS_REGION" \
123 --listen 0.0.0.0:8080 \
124 --advertise node-a.internal:8080
125```
126
127## Add nodes
128
129Start each node with the same bucket settings. Give each node a different
130`--advertise` address that the other nodes can reach. The nodes find each
131other through the leases in the bucket. There is no join command and no
132fixed membership list.
133
134The bucket supplies discovery and authority. The bucket does not supply
135network reachability. The peer HTTP protocol has a version, a body
136signature, an HMAC, a clock limit, and replay protection. celld does not
137terminate TLS. Put the advertised addresses on a private network that you
138trust, or on an encrypted overlay such as WireGuard or Tailscale. Do not
139show the peer port to the public internet.
140
141## Diagnose a fleet
142
143`celld diagnose` reads the node leases in the bucket. Then it sends a
144probe to each live peer. It does not get a lease. It does not change
145ownership.
146
147```sh
148celld diagnose \
149 --bucket "$CELLD_BUCKET" \
150 --endpoint "$S3_ENDPOINT" \
151 --region "$AWS_REGION"
152```
153
154To probe only some nodes, use `--peer NODE_ID` one or more times. The
155report identifies expired records, unsafe or incorrect advertised
156addresses, peers that it cannot reach, authentication failures, and
157protocol versions that do not agree.
158
159## Environment variables
160
161For the full list, run `celld -h`. This table shows the primary settings:
162
163| variable | purpose |
164| --- | --- |
165| `CELLD_BUCKET` | The fleet bucket. The same as `--bucket` |
166| `S3_ENDPOINT` | The S3-compatible endpoint. The same as `--endpoint` |
167| `AWS_REGION`, `AWS_DEFAULT_REGION` | The storage region |
168| `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | Explicit AWS credentials. The standard AWS credential chain is also available |
169| `CELLD_ADDR` | The listener. The same as `--listen` |
170| `CELLD_ADVERTISE` | The address that peers can reach. The same as `--advertise` |
171| `CELLD_UNSAFE_PUBLIC_ADVERTISE` | Set to `on` to permit a public peer IP |
172| `CELLD_NODE` | An explicit node-session ID |
173| `CELLD_WATCH` | The local work directory for SQLite and replication |
174| `CELLD_ESBUILD` | The path of the esbuild executable |
175| `CELLD_WORKERS` | The size of the stateless Worker pool (default: 16) |
176| `CELLD_ACTIVATIONS` | The limit for concurrent cold-cell activations (default: the Worker count or 128, the smaller value) |
177| `CELLD_WORKER_LOADER` | Bind a Worker Loader (Code Mode) at this `env` name. A Worker can then start isolates at runtime. Off unless set (experimental) |
178| `CELLD_MAX_LOADED_WORKERS` | The limit for concurrent loaded workers (default: 256) |
179| `CELLD_MAX_RESIDENT_CELLS` | The hard limit for resident cells, enforced at admission |
180| `CELLD_MAX_RSS_MB` | The memory threshold for pressure shedding (default: 80% of the available memory; 0 disables it) |
181| `CELLD_MAX_CPU_PERCENT` | The CPU threshold for pressure shedding (off unless set) |
182| `CELLD_VAR_*`, `CELLD_VARS_FILE` | Worker variable overrides |
183| `RUST_LOG` | The runtime log filter |
184
185The help output also shows the advanced tuning switches and their
186defaults.