| 1 | # celld documentation |
| 2 | |
| 3 | celld is a stateful distributed system. It runs server-side JavaScript on |
| 4 | your machines and keeps all shared data in an S3-compatible bucket that |
| 5 | you own. The JavaScript API is the same API that Cloudflare Workers and |
| 6 | 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 | An idle cell hibernates to the bucket, where it is only an object in S3 |
| 20 | and costs almost zero. A resident cell is in memory. One 8 GB node holds |
| 21 | 1,000 resident cells, so one resident cell costs approximately $0.05 each |
| 22 | month. |
| 23 | |
| 24 | The bucket is the coordinator. There is no membership protocol, no |
| 25 | failure detector, and no consensus service. One atomic write to the |
| 26 | bucket gives a node the ownership of a cell. Replication sends the SQLite |
| 27 | data of each cell to the bucket, and celld does not acknowledge a write |
| 28 | before the data is there (RPO=0). The loss of a node therefore cannot |
| 29 | lose an acknowledged write. To add a node to the fleet, point the node at |
| 30 | the 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 | |
| 48 | The installer downloads the `celld` binary. Replication occurs in the |
| 49 | celld process. A node does not need an external replicator. If your |
| 50 | project contains Worker code, `celld deploy` needs esbuild. An asset-only |
| 51 | project does not need esbuild. |
| 52 | |
| 53 | ```sh |
| 54 | curl -fsSL https://celld.dev/install.sh | sh |
| 55 | ``` |
| 56 | |
| 57 | If the installer tells you, add `~/.local/bin` to `PATH`. To install one |
| 58 | exact 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 |
| 60 | the tag of that release. The releases are on |
| 61 | [GitHub](https://github.com/denoland/celld/releases). Each release has a |
| 62 | GitHub Actions build attestation. To make sure that a downloaded file is |
| 63 | correct, run `gh attestation verify <asset> --repo denoland/celld`. |
| 64 | |
| 65 | ## Configure object storage |
| 66 | |
| 67 | celld uses the standard AWS credential chain. For Cloudflare R2, do these |
| 68 | steps. Create a bucket. Create an S3 API token that has access to that |
| 69 | bucket. Then set these variables: |
| 70 | |
| 71 | ```sh |
| 72 | export AWS_ACCESS_KEY_ID=... |
| 73 | export AWS_SECRET_ACCESS_KEY=... |
| 74 | export AWS_REGION=auto |
| 75 | export S3_ENDPOINT=https://ACCOUNT_ID.r2.cloudflarestorage.com |
| 76 | export CELLD_BUCKET=s3://YOUR-BUCKET |
| 77 | ``` |
| 78 | |
| 79 | The bucket credentials give full control of the fleet. Keep them safe. The |
| 80 | bucket contains the deployments, the SQLite replicas, the ownership |
| 81 | records, the node leases, and the peer-authentication secret. |
| 82 | |
| 83 | ## Deploy an application |
| 84 | |
| 85 | If the project contains Worker code, install `esbuild` on `PATH`. Then run |
| 86 | `celld deploy` from an applicable Wrangler project: |
| 87 | |
| 88 | ```sh |
| 89 | git clone https://github.com/denoland/celld |
| 90 | cd celld/examples/counter |
| 91 | celld 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 |
| 98 | assets. An asset project can include a Worker or be asset-only. The asset |
| 99 | functions include the assets binding, HTML handling, not-found handling, |
| 100 | worker-first routes, `_headers`, and `_redirects`. If the Wrangler |
| 101 | configuration contains an unknown key, the deploy stops with an error. See |
| 102 | the [limitations](limitations.md) for the current deployment boundary. |
| 103 | |
| 104 | ## Start a node |
| 105 | |
| 106 | For local development, the default listener is sufficient: |
| 107 | |
| 108 | ```sh |
| 109 | celld \ |
| 110 | --bucket "$CELLD_BUCKET" \ |
| 111 | --endpoint "$S3_ENDPOINT" \ |
| 112 | --region "$AWS_REGION" |
| 113 | ``` |
| 114 | |
| 115 | For a fleet node, bind the service. Advertise an address that the other |
| 116 | nodes and the ingress can reach: |
| 117 | |
| 118 | ```sh |
| 119 | celld \ |
| 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 | |
| 129 | Start 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 |
| 131 | other through the leases in the bucket. There is no join command and no |
| 132 | fixed membership list. |
| 133 | |
| 134 | The bucket supplies discovery and authority. The bucket does not supply |
| 135 | network reachability. The peer HTTP protocol has a version, a body |
| 136 | signature, an HMAC, a clock limit, and replay protection. celld does not |
| 137 | terminate TLS. Put the advertised addresses on a private network that you |
| 138 | trust, or on an encrypted overlay such as WireGuard or Tailscale. Do not |
| 139 | show 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 |
| 144 | probe to each live peer. It does not get a lease. It does not change |
| 145 | ownership. |
| 146 | |
| 147 | ```sh |
| 148 | celld diagnose \ |
| 149 | --bucket "$CELLD_BUCKET" \ |
| 150 | --endpoint "$S3_ENDPOINT" \ |
| 151 | --region "$AWS_REGION" |
| 152 | ``` |
| 153 | |
| 154 | To probe only some nodes, use `--peer NODE_ID` one or more times. The |
| 155 | report identifies expired records, unsafe or incorrect advertised |
| 156 | addresses, peers that it cannot reach, authentication failures, and |
| 157 | protocol versions that do not agree. |
| 158 | |
| 159 | ## Environment variables |
| 160 | |
| 161 | For 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 | |
| 185 | The help output also shows the advanced tuning switches and their |
| 186 | defaults. |