Cloudflare deployment: LessDB + R2 + lessdb.dev

Cloudflare deployment: LessDB + R2 + lessdb.dev

Deploy LessDB with its durable storage in Cloudflare and the docs site on lessdb.dev. You need: a Cloudflare account (R2 enabled), the wrangler CLI authenticated, and one Linux/macOS machine (any size — a Raspberry Pi works; the 192.168.0.2 instance in this repo's benchmarks is 28 cores).

1. Create the R2 buckets

wrangler r2 bucket create lessdb-shared     # database SharedMergeTree storage
wrangler r2 bucket create lessdb-downloads  # public release binaries

2. Create an R2 API token for the database node

Dashboard → R2 → Manage R2 API Tokens → Create API Token, or via the API:

curl -X POST "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/r2/temp_auth_tokens" \
  -H "Authorization: Bearer <token>" \
  --data '{"name":"lessdb-node-01","ttl":0}'

The result contains access_key_id / secret_access_key (S3-style). Grant the token Object Read & Write on lessdb-shared only.

3. Install LessDB on the node

Pick a release from lessdb.dev/downloads (the cloud build includes the S3 backend) or build from source:

cargo install --path crates/less-cli --features less-cli/cloud

4. Point the node at R2

R2 speaks the S3 API, and LessDB's SharedMergeTree engine writes immutable parts straight to object storage:

export AWS_ACCESS_KEY_ID=<access_key_id>
export AWS_SECRET_ACCESS_KEY=<secret_access_key>
export AWS_ENDPOINT_URL=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
export AWS_ALLOW_HTTP=true   # not needed, R2 is HTTPS — shown for completeness

less init --dir /var/lib/lessdb --shared s3://lessdb-shared/lessdb \
    --memory-limit 40GiB
less create --dir /var/lib/lessdb \
    "CREATE TABLE events (ts Timestamp, host Utf8, cpu Float64, payload Utf8)
     ENGINE=SharedMergeTree ORDER BY (host, ts) TTL ts INTERVAL 30 DAY"

From here less insert, less sql, and less optimize all land in R2. The node's local disk is pure scratch: kill it, start a new one, and the new node discovers every table by listing the bucket.

5. Run it as a service

# /etc/systemd/system/lessdb.service
[Unit]
Description=LessDB
After=network-online.target

[Service]
Environment=AWS_ACCESS_KEY_ID=<id>
Environment=AWS_SECRET_ACCESS_KEY=<secret>
Environment=AWS_ENDPOINT_URL=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
ExecStart=/usr/local/bin/less server --dir /var/lib/lessdb --listen 0.0.0.0:7080
Restart=on-failure
MemoryMax=80%

[Install]
WantedBy=multi-user.target
systemctl enable --now lessdb
curl -s localhost:7080/health
curl -s -X POST localhost:7080/v1/sql -d "SELECT count(*) FROM events"

6. Second node = add compute, not replicas

Repeat steps 3–5 on another machine with the same bucket prefix. There is no replication protocol to configure: manifests and parts live in R2, multi-writer safety comes from CAS merge-claims in the bucket's metastore. Both nodes can OPTIMIZE concurrently without double-merging.

7. Custom domain and TLS

Put a CDN/ingress in front (Cloudflare Tunnel or a reverse proxy with less server --tls-cert/--tls-key). Prometheus at /metrics, LDAP/AD roles via less init --auth if the API is exposed.

8. Verify

less stats --dir /var/lib/lessdb events     # rows, parts
less cache --dir /var/lib/lessdb            # block-cache hit stats
curl -s localhost:7080/metrics | grep lessdb_parts