| 1 | # celld documentation |
| 2 | |
| 3 | celld is a stateful distributed system. It runs server-side JavaScript on |
| 4 | your machines. It keeps all shared data in an S3-compatible or Google |
| 5 | Cloud Storage bucket that you own. The JavaScript API is the same API |
| 6 | that Cloudflare Workers and Durable Objects supply. |
| 7 | |
| 8 | In Cloudflare terms, a cell is a Durable Object: a small server with a |
| 9 | name and a private SQLite database. You make one cell for each user, each |
| 10 | document, each chat room, or each AI agent. A cell serves HTTP, holds |
| 11 | WebSocket connections, sets alarms, and makes outbound connections. Each |
| 12 | cell runs on one thread, so two requests to the same cell never run at |
| 13 | the same instant. A second request can interleave only while the first |
| 14 | awaits, and storage operations are synchronous, so a storage operation |
| 15 | never interleaves at all. The data in a cell therefore stays consistent. |
| 16 | Cells share no database, and the application divides into cells from the |
| 17 | start. |
| 18 | |
| 19 | A cell has the same states as a Durable Object. A **resident** cell is in |
| 20 | memory: it is **active** while it does work, and **idle** when it waits. |
| 21 | celld removes an idle cell from memory. A cell that then keeps its |
| 22 | hibernatable WebSocket clients, and stays on its node, is **hibernated**. |
| 23 | A cell that no node holds is **inactive**. An inactive cell is only an |
| 24 | object in the bucket, so it costs almost zero, and every cell starts in |
| 25 | this state. |
| 26 | |
| 27 | Memory holds nothing across these transitions, so the constructor runs |
| 28 | again on the next event. A hibernated cell therefore starts as a cold |
| 29 | start does, and only two facts separate the two states: the WebSocket |
| 30 | clients stay connected, and the cell stays on its node. |
| 31 | |
| 32 | One 8 GB node holds 1,000 resident cells, so one resident cell costs |
| 33 | approximately $0.05 each month. |
| 34 | |
| 35 | The bucket is the coordinator. There is no membership protocol, no |
| 36 | failure detector, and no consensus service. One atomic write to the |
| 37 | bucket gives a node the ownership of a cell. Replication sends the SQLite |
| 38 | data of each cell to the bucket, and celld does not acknowledge a write |
| 39 | before the data is there (RPO=0). The loss of a node therefore cannot |
| 40 | lose an acknowledged write. To add a node to the fleet, point the node at |
| 41 | the bucket. The [ownership and fencing](fencing.md) page gives the full |
| 42 | mechanism and the exact properties that the bucket must provide. |
| 43 | |
| 44 | ## What do you build with cells |
| 45 | |
| 46 | A cell fits a workload that divides into named, stateful units: |
| 47 | |
| 48 | - **Real-time applications.** A multiplayer game, a chat room, or a |
| 49 | collaborative document is one cell. The cell holds the WebSocket |
| 50 | connections and the state of one room, so the room needs no lock and |
| 51 | no external message bus. |
| 52 | - **Agents.** Each AI agent is one cell. The cell holds the memory, the |
| 53 | schedule, and the inbox of one agent in its own SQLite database, and |
| 54 | an idle agent hibernates to the bucket, so a large agent fleet costs |
| 55 | almost nothing between events. |
| 56 | - **Sharded web applications.** One cell for each user, each tenant, or |
| 57 | each device shards the application from the start. The contention of |
| 58 | one shared database does not appear, because no shared database |
| 59 | exists. |
| 60 | |
| 61 | ## Contents |
| 62 | |
| 63 | - [What do you build with cells](#what-do-you-build-with-cells) |
| 64 | - [Install](#install) |
| 65 | - [Configure object storage](#configure-object-storage) |
| 66 | - [Deploy an application](#deploy-an-application) |
| 67 | - [Start a node](#start-a-node) |
| 68 | - [Add nodes](#add-nodes) |
| 69 | - [Diagnose a fleet](#diagnose-a-fleet) |
| 70 | - [Environment variables](#environment-variables) |
| 71 | - [Cloudflare compatibility](cloudflare-compat.md) |
| 72 | - [Ownership and fencing](fencing.md) |
| 73 | - [limitations](limitations.md) |
| 74 | - [Security](security.md) |
| 75 | - [Telemetry](telemetry.md) |
| 76 | - [Testing](testing.md) |
| 77 | - [WebAssembly](wasm.md) |
| 78 | |
| 79 | ## Install |
| 80 | |
| 81 | The installer downloads the `celld` binary. Replication occurs in the |
| 82 | celld process. A node does not need an external replicator. If your |
| 83 | project contains Worker code, `celld deploy` needs esbuild. An asset-only |
| 84 | project does not need esbuild. |
| 85 | |
| 86 | ```sh |
| 87 | curl -fsSL https://celld.dev/install.sh | sh |
| 88 | ``` |
| 89 | |
| 90 | If the installer tells you, add `~/.local/bin` to `PATH`. To install one |
| 91 | exact release, set `CELLD_VERSION` to the tag of that release, for example |
| 92 | `v0.0.1`. To go back to a previous release, run the installer again with |
| 93 | the tag of that release. The releases are on |
| 94 | [GitHub](https://github.com/denoland/celld/releases). Each release has a |
| 95 | GitHub Actions build attestation. To make sure that a downloaded file is |
| 96 | correct, run `gh attestation verify <asset> --repo denoland/celld`. |
| 97 | |
| 98 | ## Configure object storage |
| 99 | |
| 100 | For an S3-compatible bucket, celld uses the standard AWS credential |
| 101 | chain. For Cloudflare R2, do these steps. Create a bucket. Create an S3 |
| 102 | API token that has access to that bucket. Then set these variables: |
| 103 | |
| 104 | ```sh |
| 105 | export AWS_ACCESS_KEY_ID=... |
| 106 | export AWS_SECRET_ACCESS_KEY=... |
| 107 | export AWS_REGION=auto |
| 108 | export S3_ENDPOINT=https://ACCOUNT_ID.r2.cloudflarestorage.com |
| 109 | export CELLD_BUCKET=s3://YOUR-BUCKET |
| 110 | ``` |
| 111 | |
| 112 | For Google Cloud Storage, celld uses Application Default Credentials. |
| 113 | Create a bucket. Then authenticate with `gcloud auth application-default |
| 114 | login`, or point `GOOGLE_APPLICATION_CREDENTIALS` at a service-account |
| 115 | key that has access to the bucket. Then set the bucket: |
| 116 | |
| 117 | ```sh |
| 118 | export CELLD_BUCKET=gs://YOUR-BUCKET |
| 119 | ``` |
| 120 | |
| 121 | A `gs://` bucket takes no `S3_ENDPOINT` and no `AWS_*` credentials, and |
| 122 | celld ignores the storage region. |
| 123 | |
| 124 | On a Compute Engine instance, celld can use the attached service |
| 125 | account. The access scopes of the instance cap this credential, and the |
| 126 | default scope permits only storage reads. Create the instance with the |
| 127 | `cloud-platform` scope, so the IAM role of the service account controls |
| 128 | the access. |
| 129 | |
| 130 | The bucket credentials give full control of the fleet. Keep them safe. The |
| 131 | bucket contains the deployments, the SQLite replicas, the ownership |
| 132 | records, the node leases, and the peer-authentication secret. |
| 133 | |
| 134 | A bucket value can add a key prefix: `s3://YOUR-BUCKET/PREFIX`. Every |
| 135 | object of the fleet then goes below `PREFIX/`, so two fleets can share one |
| 136 | bucket. A bucket value without a prefix keeps the objects at the root of |
| 137 | the bucket, therefore an existing fleet does not move its data. |
| 138 | |
| 139 | The store must provide conditional writes and read-after-write |
| 140 | consistency, because the ownership records depend on them. Amazon S3, |
| 141 | Cloudflare R2, Google Cloud Storage, Azure Blob Storage, and Tigris |
| 142 | qualify; MinIO (community edition), Backblaze B2, Hetzner, and |
| 143 | DigitalOcean Spaces do not. See [ownership and fencing](fencing.md) |
| 144 | for the exact requirements. |
| 145 | |
| 146 | ## Deploy an application |
| 147 | |
| 148 | If the project contains Worker code, install `esbuild` on `PATH`. Then run |
| 149 | `celld deploy` from an applicable Wrangler project: |
| 150 | |
| 151 | ```sh |
| 152 | git clone https://github.com/denoland/celld |
| 153 | cd celld/examples/counter |
| 154 | celld deploy . \ |
| 155 | --bucket "$CELLD_BUCKET" \ |
| 156 | --endpoint "$S3_ENDPOINT" \ |
| 157 | --region "$AWS_REGION" |
| 158 | ``` |
| 159 | |
| 160 | `celld deploy` accepts module Workers, Durable Object bindings, and static |
| 161 | assets. An asset project can include a Worker or be asset-only. The asset |
| 162 | functions include the assets binding, HTML handling, not-found handling, |
| 163 | worker-first routes, `_headers`, and `_redirects`. If the Wrangler |
| 164 | configuration contains an unknown key, the deploy stops with an error. See |
| 165 | the [limitations](limitations.md) for the current deployment boundary. |
| 166 | |
| 167 | ## Start a node |
| 168 | |
| 169 | For local development, the default listener is sufficient: |
| 170 | |
| 171 | ```sh |
| 172 | celld \ |
| 173 | --bucket "$CELLD_BUCKET" \ |
| 174 | --endpoint "$S3_ENDPOINT" \ |
| 175 | --region "$AWS_REGION" |
| 176 | ``` |
| 177 | |
| 178 | For a fleet node, bind the public and internal listeners separately. The |
| 179 | ingress can reach the public listener, and the other nodes can reach the |
| 180 | internal listener: |
| 181 | |
| 182 | ```sh |
| 183 | celld \ |
| 184 | --bucket "$CELLD_BUCKET" \ |
| 185 | --endpoint "$S3_ENDPOINT" \ |
| 186 | --region "$AWS_REGION" \ |
| 187 | --listen 0.0.0.0:8080 \ |
| 188 | --internal-listen 10.0.0.12:8081 \ |
| 189 | --advertise node-a.internal:8081 |
| 190 | ``` |
| 191 | |
| 192 | An explicit advertised address requires an explicit internal-listener address. |
| 193 | Set both command-line options, or use their equivalent environment variables. |
| 194 | celld also rejects an explicit non-loopback public listener without an explicit |
| 195 | internal listener. This rule identifies an obsolete one-listener configuration. |
| 196 | |
| 197 | celld cannot verify that an advertised hostname or a translated port reaches |
| 198 | the internal listener. You must route the advertised address to the internal |
| 199 | listener, and you must not route it to the public Worker listener. |
| 200 | |
| 201 | ## Add nodes |
| 202 | |
| 203 | Start each node with the same bucket settings. Give each internal listener a |
| 204 | different address that the other nodes can reach. Set `--advertise` to that |
| 205 | internal address. The nodes find each other through the leases in the bucket. |
| 206 | There is no join command and no fixed membership list. |
| 207 | |
| 208 | The bucket supplies discovery and authority. The bucket does not supply |
| 209 | network reachability. The peer HTTP protocol has a version, a body |
| 210 | signature, an HMAC, a clock limit, and replay protection. celld does not |
| 211 | terminate TLS. Put the advertised addresses on a private network that you |
| 212 | trust, or on an encrypted overlay such as WireGuard or Tailscale. The internal |
| 213 | listener also has an unauthenticated operator API, so do not show it to the |
| 214 | public internet. See the [security](security.md) page for the complete boundary. |
| 215 | |
| 216 | ## Shut down and roll out a node |
| 217 | |
| 218 | celld shuts a node down gracefully on SIGTERM or SIGINT, and these are the |
| 219 | signals `systemctl stop`, `docker stop`, and a Kubernetes pod delete send. |
| 220 | The `/__celld/health` path reports the node as unhealthy, so a load balancer |
| 221 | stops routing to it. The node |
| 222 | answers each new request with a 503 and closes the connection, so a client |
| 223 | retries on a healthy node. The node then hands every resident cell to a |
| 224 | peer by releasing its ownership, and it finishes the requests already in |
| 225 | flight. A cell that serves a request is handed off when that request |
| 226 | finishes. A peer takes over each released cell at once, so the node leaves |
| 227 | without the takeover gap of an abrupt kill. |
| 228 | |
| 229 | The internal listener continues to accept `/state` requests during the drain. |
| 230 | The response reports the `occupied`, `evicting`, and `restoring` values. The |
| 231 | public health response identifies the active drain with a 503 status. |
| 232 | |
| 233 | The handoff runs at most `CELLD_RELEASES` releases at the same time, and |
| 234 | the default is 128. This bound keeps a node with many cells from flooding |
| 235 | the object store at shutdown. `CELLD_SHUTDOWN_DRAIN_MS` bounds the whole |
| 236 | drain, and its default is 25000. The node exits when the handoff and the |
| 237 | in-flight requests finish, or when this many milliseconds pass, whichever |
| 238 | is first — an idle node exits immediately. You must set it below the stop |
| 239 | grace of your orchestrator, such as systemd `TimeoutStopSec` or Kubernetes |
| 240 | `terminationGracePeriod`, so the orchestrator does not send SIGKILL. |
| 241 | |
| 242 | To roll out a new version, use the rolling update of your orchestrator: |
| 243 | stop each node with SIGTERM, wait for its replacement to report healthy, |
| 244 | then move to the next node. celld has no rollout command, because the |
| 245 | health signal lets the orchestrator pace the roll. |
| 246 | |
| 247 | The upgrade from v0.1.0 to v0.2.0 must not be a rolling update. Stop |
| 248 | every v0.1.0 node, then start the v0.2.0 nodes. Two changes require |
| 249 | this: v0.2.0 nodes advertise the internal listener, so ownership |
| 250 | records that v0.1.0 nodes wrote name an address that v0.1.0 peers can |
| 251 | not follow to a v0.2.0 node; and v0.2.0 compacts replicated data into |
| 252 | block objects that a v0.1.0 reader can not restore. A fleet must not |
| 253 | mix the two versions. |
| 254 | |
| 255 | The internal listener also provides an alpha operator API. `/state` reports the |
| 256 | node state, and `POST /shutdown` starts the same graceful handoff. The |
| 257 | `POST /shutdown?handoff=preserve` request prepares a clean same-node reload and |
| 258 | keeps the ownership records. A release can change this API, so keep the |
| 259 | operator tooling and the celld release together. |
| 260 | |
| 261 | ## Diagnose a fleet |
| 262 | |
| 263 | `celld diagnose` reads the node leases in the bucket. Then it sends a |
| 264 | probe to each live peer. It does not get a lease. It does not change |
| 265 | ownership. |
| 266 | |
| 267 | ```sh |
| 268 | celld diagnose \ |
| 269 | --bucket "$CELLD_BUCKET" \ |
| 270 | --endpoint "$S3_ENDPOINT" \ |
| 271 | --region "$AWS_REGION" |
| 272 | ``` |
| 273 | |
| 274 | To probe only some nodes, use `--peer NODE_ID` one or more times. The |
| 275 | report identifies expired records, unsafe or incorrect advertised |
| 276 | addresses, peers that it cannot reach, authentication failures, and |
| 277 | protocol versions that do not agree. |
| 278 | |
| 279 | Each node line also shows `restoring`. This value counts each cold route that |
| 280 | holds an activation permit or waits for one. A capacity waiter already holds |
| 281 | a permit, so the value counts each cold route once. During a rolling update, |
| 282 | you must wait for every node to report `restoring=0` before you restart the |
| 283 | next node. Therefore, one restart's cold work finishes before the next restart |
| 284 | removes more warm capacity. |
| 285 | |
| 286 | ## Environment variables |
| 287 | |
| 288 | For the full list, run `celld -h`. This table shows the primary settings: |
| 289 | |
| 290 | | variable | purpose | |
| 291 | | --- | --- | |
| 292 | | `CELLD_BUCKET` | The fleet bucket, and an optional key prefix. The same as `--bucket` | |
| 293 | | `S3_ENDPOINT` | The S3-compatible endpoint. The same as `--endpoint` | |
| 294 | | `AWS_REGION`, `AWS_DEFAULT_REGION` | The storage region | |
| 295 | | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | Explicit AWS credentials. The standard AWS credential chain is also available | |
| 296 | | `GOOGLE_APPLICATION_CREDENTIALS`, `GOOGLE_SERVICE_ACCOUNT_KEY` | Google credentials for a `gs://` bucket. Application Default Credentials are also available | |
| 297 | | `CELLD_ADDR` | The public Worker listener. The same as `--listen` | |
| 298 | | `CELLD_INTERNAL_ADDR` | The peer and operator listener. The same as `--internal-listen` | |
| 299 | | `CELLD_ADVERTISE` | The internal address that peers can reach. The same as `--advertise` | |
| 300 | | `CELLD_UNSAFE_PUBLIC_ADVERTISE` | Set to `1` to permit a literal public IP in `CELLD_ADVERTISE`. This setting does not resolve a DNS name or restrict the internal listener | |
| 301 | | `CELLD_NODE` | An explicit node-session ID | |
| 302 | | `CELLD_WATCH` | The local work directory for SQLite and replication | |
| 303 | | `CELLD_ESBUILD` | The path of the esbuild executable | |
| 304 | | `CELLD_ACTIVATIONS` | The limit for concurrent cold-cell activations (default: the available CPU count or 128, whichever is smaller) | |
| 305 | | `CELLD_OPERATION_DEADLINE_MS` | The deadline for a non-restore operation (default: 15000) | |
| 306 | | `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) | |
| 307 | | `CELLD_MAX_LOADED_WORKERS` | The limit for concurrent loaded workers (default: 256) | |
| 308 | | `CELLD_MAX_RESIDENT_CELLS` | The hard limit for resident cells, enforced at admission | |
| 309 | | `CELLD_MAX_RSS_MB` | The memory threshold for pressure shedding (default: 80% of the available memory; 0 disables it) | |
| 310 | | `CELLD_OUTPUT_GATE` | The default is `1`, so celld proves each write durable before it acknowledges the write. Set `0` to remove the replication wait and accept possible loss of an acknowledged write | |
| 311 | | `CELLD_LTX_COMPACTION` | The default is `1`: celld creates additive L1 objects, and a takeover reads tens of objects instead of thousands. Set `0` on every node of a mixed fleet until all nodes can read v0.5.2 block objects, because an old reader cannot take over a cell after its first L1 publication | |
| 312 | | `CELLD_LTX_COMPACTION_MIN_TXIDS` | The durable TXID distance that queues an L1 attempt (default: 256) | |
| 313 | | `CELLD_LTX_COMPACTIONS` | The node-wide limit for concurrent L1 attempts (default: 2) | |
| 314 | | `CELLD_VAR_*`, `CELLD_VARS_FILE` | Worker variable overrides | |
| 315 | | `RUST_LOG` | The runtime log filter | |
| 316 | |
| 317 | The help output also shows the advanced tuning switches and their |
| 318 | defaults. |
| 319 | |
| 320 | An unset variable selects its documented default. A Boolean variable accepts |
| 321 | only `0` or `1`. celld exits during startup when a supplied value is invalid. |