Linora

Deploying Linora

Cloud-agnostic notes for running every tier in production: any container platform (Kubernetes, ECS, Nomad, or plain VMs with Docker), a Postgres 18 compatible database, and an S3-compatible object store. Related docs: architecture in overview.md and ADR 0021 (topology); images in ADR 0903; footprint in build.md; security controls in security.md.

docker-compose.prod.yml is a working single-host version of everything below, minus TLS and replicas. Read it next to this page.

Topology

 Internet ── TLS 1.2+ (HSTS) ── Edge LB ──┬── /v1/realtime?file=F ── hash(F) ──► realtime instances (L4/WSS, PROXY v2)
                                          ├── /v1/*  ─────────────────────────► api replicas (stateless)
                                          ├── /mcp   ─────────────────────────► mcp replicas (optional, hosted agents)
                                          └── /*     ─────────────────────────► web (static; or a CDN)
 Private network only:
   api ── ws ──► internal realtime LB (same hash(F) routing) ──► realtime     (HTTP op batches, ADR 0303)
   api ── http ──► doc workers (the API picks one by rendezvous hash of pageId; no LB, ADR 0304)
   doc workers ── ws ──► internal realtime LB (follow live pages)
   compactor processes ── Postgres + blob store (job queue, FOR UPDATE SKIP LOCKED)
   every tier ── Postgres (own role) ; api/realtime/docworker/compactor ── blob store
   Prometheus ──► metrics ports (never routed by the edge)
Tier Image / command Replicas Routed by Ports
web web (nginx, uid 101) 2+, or a CDN in front any 8080
api api 2+, stateless any (round robin) 8787 public, 9465 metrics
realtime realtime 1 per box (8 vCPU / 16 GB target, ADR 0020) file id (consistent hash of ?file=) 8788 public WS + /healthz, 9464 metrics
doc workers docworker (--mode=worker) N, private the API hashes pageId over LINORA_DOCWORKER_URLS 8790 private, 9466 metrics
compactor docworker with --mode=compactor 1+ (a long-running job loop), plus 1+ large-memory compactor for big pages none (claims jobs) 9467 metrics
mcp mcp (LINORA_MCP_TRANSPORT=http) 1+, stateless sessions per agent any 8789
migrate api image: --no-strip-types packages/server-common/src/migrate.js run once per release - -

Realtime routing is the one hard requirement. Every socket of a file must reach the instance that owns its rooms, from browsers and from the API and doc workers too. Hash fileId on the file query parameter with a consistent hash (HAProxy balance uri/hash-type consistent on the param, nginx hash $arg_file consistent, Envoy ring hash or Maglev). Adding an instance then moves only ~1/N of files; their clients reconnect and catch up. Put the same rule on an internal listener for LINORA_REALTIME_INTERNAL_URL, which the API and doc workers use.

The compactor is a job, not a service. Each process claims one page at a time, exits 75 after LINORA_COMPACTOR_MAX_JOBS jobs or above its memory cap, and expects to be restarted (restart policy always, or a Deployment). Scale by process count; claims use SKIP LOCKED. A scheduled job (CronJob) also works if it runs often enough to keep tails short (tail thresholds in doc-workers.md).

Images and commands

Build from the repo root: docker build -f deploy/Dockerfile --target <api|realtime|docworker|mcp|web> ..

Configuration

All settings come from the environment. Tiers refuse to start when a required setting is missing or invalid and report every problem at once (ADR 0023). With NODE_ENV unset or production, the defaults are secure: Secure __Host- cookies, HSTS, no default origins, info logs, invite-only signup. A production tier also refuses the development credentials this repo publishes (the dev DATABASE_URL password and S3 secret from .env.example, docker-compose.yml and CI; ADR 0906). LINORA_ALLOW_DEV_SECRETS=1 lifts that for tests and benchmarks only; never set it in a deployment.

Variable Tiers Production value
DATABASE_URL all but mcp the tier’s own login (see Database roles); migrate uses the owner
LINORA_TOKEN_KEYS_RT api, realtime derived keyring (see Secrets)
LINORA_TOKEN_KEYS_CG realtime derived keyring
LINORA_TOKEN_KEYS_SVC_API api, docworker derived keyring
LINORA_TOKEN_KEYS_SVC_DOCWORKER docworker, realtime derived keyring
LINORA_BLOB_STORE, LINORA_S3_ENDPOINT, LINORA_S3_REGION, LINORA_S3_BUCKET, LINORA_S3_ACCESS_KEY_ID, LINORA_S3_SECRET_ACCESS_KEY, LINORA_S3_FORCE_PATH_STYLE api, realtime, docworker, compactor s3, your endpoint and bucket. Give the compactor a read-write bucket user and the readers (api, realtime, docworker) a read-only one; with local, mount the blob directory read-only in the readers (ADR 0906)
LINORA_TRUSTED_PROXIES api, realtime CIDRs of the LBs (and the hosted MCP) whose X-Forwarded-For / PROXY header is honoured
LINORA_API_HOST / LINORA_REALTIME_HOST / LINORA_DOCWORKER_HOST api / realtime / docworker, compactor 0.0.0.0 in a container (the docworker default is 127.0.0.1)
LINORA_API_METRICS_HOST, LINORA_REALTIME_METRICS_HOST, LINORA_DOCWORKER_METRICS_HOST, LINORA_COMPACTOR_METRICS_HOST each tier private interface, or 0.0.0.0 in a container that sits only on a private network whose metrics port is never published or routed (SR-18). A container that is also on a client-facing network (the prod-like api and realtime) keeps the 127.0.0.1 default (ADR 0906)
LINORA_REALTIME_URL api public wss://app.example.com (returned to clients in realtime tokens)
LINORA_REALTIME_SAME_ORIGIN api 1 when the edge serves /v1/realtime on every allowed origin: a token requested from an allowed origin then carries that origin’s own ws(s):// URL, others get LINORA_REALTIME_URL (ADR 0905). Off by default
LINORA_REALTIME_INTERNAL_URL api, docworker internal realtime LB, e.g. ws://realtime-internal:8788
LINORA_DOCWORKER_URLS api every doc worker’s URL, comma-separated (stable names: a StatefulSet or fixed hosts)
LINORA_ALLOWED_ORIGINS api https://app.example.com
LINORA_COOKIE_INSECURE_ORIGINS api empty. Only for plain-HTTP LAN origins of a local stack: their requests get non-Secure, unprefixed cookies (ADR 0905)
LINORA_SIGNUP, LINORA_SIGNUP_ALLOWLIST api invite + allowed addresses/domains (the default in production)
LINORA_REALTIME_GATEWAYS / LINORA_REALTIME_OWNERS realtime default 5 / 2 on Linux; size to the box (ADR 0020)
LINORA_DOCWORKER_MAX_BYTES, LINORA_COMPACTOR_MAX_BYTES docworker, compactor LRU/job caps; the RSS guard restarts at 1.5x + 256 MiB, so set the memory limit above that
LINORA_URL, LINORA_MCP_HOST, LINORA_MCP_TRUST_PROXY mcp internal API URL, 0.0.0.0, the number of proxies in front
LINORA_WEB_CONNECT_SRC, LINORA_WEB_HSTS web 'self' wss://app.example.com: always name the realtime origin from LINORA_REALTIME_URL in wss form, even on the same origin (not every browser covers ws(s) with ‘self’); HSTS on

Full lists with defaults: .env.example and each module doc. Unknown variables are ignored, so check spelling against those.

Secrets

Postgres

Blob store (S3-compatible)

Edge and TLS

Health and readiness

Tier Liveness Readiness
api GET :9465/healthz same, plus Postgres reachable (a failing DB shows as 5xx on /v1)
realtime GET :8788/healthz same endpoint: it answers 503 while draining, so take the instance out of rotation on non-200
docworker GET :9466/healthz same (503 while draining)
compactor GET :9467/healthz none (not routed)
mcp GET :8789/healthz same
web GET :8080/healthz same

Suggested probes: period 10 s, timeout 2 s, failure threshold 3. Give realtime and the compactor a startup grace of 30 s.

Scaling

Rollout

  1. Build and push the images; run migrate (and roles.sql on the first deploy).
  2. Roll api, mcp, web, doc workers and compactor with a normal rolling update. They drain on SIGTERM: the api closes its listeners and finishes requests (grace 15 s); doc workers stop serving; the compactor finishes its current job (grace 60 s).
  3. Roll realtime one instance at a time. SIGTERM triggers the drain (realtime.md):
    • it stops accepting (/healthz returns 503, so the LB stops routing to it);
    • it commits pending journal batches and delivers ACKs;
    • it sends every client going_away with a random retry delay up to 60 s (DRAIN_SPREAD_MS), so reconnects spread out instead of stampeding;
    • its threads then exit. Allow a 30 s termination grace, wait for the replacement to pass /healthz, and keep 60 s or more between instances so the previous wave has reconnected. Clients resubscribe with sinceSeq and lose nothing.
  4. Protocol or rules bumps: a PROTOCOL_VERSION or DOC_RULES_VERSION bump makes old clients reload (version_mismatch). For DOC_RULES_VERSION, compact every page with a non-empty tail before switching realtime (ADR 0019), and ship the web app in the same release.
  5. Roll back by redeploying the previous image tags. Migrations are additive, so the previous code still runs.

Backups and restore

Observability

Local prod-like stack

docker-compose.prod.yml runs everything above on one host: compiled images, per-tier DB logins and keys, an internal network, and an nginx edge on http://127.0.0.1:8080 (other devices too, in LAN mode). It has no TLS, so LINORA_WEB_HSTS is empty, and signup is open.

Deploys use committed code only. npm run prod:up (deploy/prod-up.mjs) exports a commit with git archive into a fresh temp dir, builds every image from that export, and runs docker compose -p <project> --env-file .env.prod up -d --build --wait --remove-orphans there. Uncommitted work in the tree, yours or another agent’s, never ships, and the script says how many changes it left out. The project name, .env.prod and the volumes stay the same, so data survives. Migrations run as the migrate one-shot, and only containers whose image or config changed are recreated (typically 15-30 s of disruption, realtime clients reconnect on their own). Images carry the label org.opencontainers.image.revision=<sha>. The edge config and roles.sql are baked into images (edge, db-roles targets), so the running stack never depends on the temp export.

The project is LINORA_PROD_PROJECT in .env.prod, which npm run prod:env writes (default linora-prod). prod:up reads it, and so do prod:ps, prod:logs, prod:down and any docker compose -f docker-compose.prod.yml --env-file .env.prod ..., through the compose file’s name:. Volumes, networks and images belong to the project: an install with data must keep its name, or it starts over with empty volumes.

Task Command
First time: secrets npm run prod:env (writes .env.prod)
Build + start, or update to the latest commit npm run prod:up (another commit: npm run prod:up -- --ref <ref>). It stops before building when another program holds the edge port, and prints the URL when the stack is healthy
Use another port than 8080 set LINORA_PROD_PORT in .env.prod, then npm run prod:up
Behind a TLS-intercepting proxy the proxy CA is read from LINORA_BUILD_CA, else NODE_EXTRA_CA_CERTS, e.g. LINORA_BUILD_CA=~/certs/proxy-root-ca.pem npm run prod:up (Troubleshooting)
Deployed revision docker inspect -f '{{index .Config.Labels "org.opencontainers.image.revision"}}' linora-prod-api-1 (<project>-api-1)
Status npm run prod:ps
Logs npm run prod:logs [-- api realtime ...]
Restart one tier docker compose -f docker-compose.prod.yml --env-file .env.prod restart <service>
Smoke test node deploy/smoke.mjs http://127.0.0.1:8080 (any origin the stack serves, e.g. a LAN host)
LAN mode on / off set / empty LINORA_PROD_LAN_HOSTS in .env.prod, then npm run prod:up (below)
Stop (keep data) npm run prod:down
Start again after a stop npm run prod:up. Without a stop, the stack restarts by itself whenever Docker starts (restart: unless-stopped)
Stop and delete data npm run prod:down -- -v
Remove everything npm run prod:down -- -v --rmi local (containers, networks, volumes and the images built for this project; shared base images such as postgres stay, docker image prune -a removes unused ones), then delete the clone
Throwaway copy (tests) npm run prod:up -- --project <name> --env-file <file>, where the file sets its own LINORA_PROD_PROJECT=<name>, LINORA_PROD_PORT and LINORA_PROD_EDGE_SUBNET, so later compose commands with that file reach the copy, not your stack

Data lives in the project’s pgdata, s3data and blobs volumes.

Before anyone else can reach it. The stack speaks plain HTTP and, by default, lets anyone who reaches it sign up.

LAN mode: other devices on the same network

Off by default: the edge is published on 127.0.0.1 only. To open the stack from another laptop or a phone on the same Wi-Fi (ADR 0905):

  1. Find this machine’s addresses: ipconfig getifaddr en0 (Wi-Fi IP, changes with DHCP) and echo "$(scutil --get LocalHostName).local" (Bonjour name; survives IP changes, but only while the Mac advertises it, which managed Macs may turn off).
  2. In .env.prod: LINORA_PROD_LAN_HOSTS=192.168.1.20,my-mac.local (IPv4 addresses or names, comma-separated, no scheme or port).
  3. npm run prod:up (add LINORA_BUILD_CA=... behind a TLS-intercepting proxy). Only api, web and edge are recreated. prod-up prints the URLs. It warns when a listed IP is no longer this machine’s, or a listed name does not resolve to it.
  4. On the other device, open http://my-mac.local:8080 or http://192.168.1.20:8080, sign up or log in, and open a file.
  5. Check from this machine: node deploy/smoke.mjs http://192.168.1.20:8080.

What it changes:

Firewall: with the macOS application firewall on, Docker Desktop’s com.docker.backend accepts the connections when “Automatically allow downloaded signed software” is enabled (the default). Otherwise macOS asks once whether it may accept incoming connections: answer Allow. “Block all incoming connections” must be off. A corporate VPN or zero-trust client may also block peer-to-peer LAN traffic.

Trade-off: this is plain HTTP. Anyone on the same network can read passwords, session cookies and documents in transit. While LAN mode is on, the edge listens on every network the machine joins, and signup is open. Turn it off on networks you don’t trust: empty LINORA_PROD_LAN_HOSTS, then npm run prod:up. If a session may have been exposed, revoke it in account settings (/v1/me/sessions). Docker Desktop shows every client to the edge as one address (192.168.65.1 with the 0.0.0.0 bind), so all devices share the per-IP limits (10 sign-ins, then 1 per 6 s).

When the IP changes: a .local URL keeps working if the Mac advertises its name. Otherwise, reserve the IP for this Mac in the router’s DHCP settings, or update LINORA_PROD_LAN_HOSTS and run npm run prod:up. A bare docker compose ... up without prod-up drops back to 127.0.0.1-only (the LAN variables are derived by deploy/lan.mjs).

Linux and Windows (WSL 2)

The prod-like stack is developed and checked on macOS with Docker Desktop. On Linux and Windows the same commands apply, with these differences:

Troubleshooting

| Symptom | Cause and fix | |—|—| | prod-up: port 8080 is already in use by another program, or Docker’s Bind for ...:8080 failed: port is already allocated | Another program, or another Linora stack, holds the port. Set LINORA_PROD_PORT=8081 in .env.prod, run npm run prod:up again, and use the new port in every URL (browser, smoke test, MCP). lsof -nP -iTCP:8080 -sTCP:LISTEN shows what holds it. | | Cannot connect to the Docker daemon or failed to connect to the docker API ... check if the daemon is running | Docker isn’t running. Start Docker Desktop (macOS: open -a Docker) or the service (Linux: sudo systemctl start docker), wait until docker info answers, and run the command again. | | prod-up: docker is not installed or not on PATH | Install Docker (see the Quickstart requirements). | | Pool overlaps with other one on this address space | The edge network’s fixed subnet, 172.31.250.0/24, is taken by another Docker network (a second Linora stack, for example) or a VPN route. Set LINORA_PROD_EDGE_SUBNET in .env.prod to a free private /24, such as 172.31.251.0/24, and run npm run prod:up. | | npm ci or the image build fails with SELF_SIGNED_CERT_IN_CHAIN, UNABLE_TO_GET_ISSUER_CERT_LOCALLY or unable to get local issuer certificate | A TLS-intercepting proxy (common on company networks and with some security software) re-signs HTTPS with its own root CA. Get that CA as a PEM file (your IT team has it), then export NODE_EXTRA_CA_CERTS=/path/to/proxy-root-ca.pem before npm ci and npm run prod:up. prod-up hands it to the image build as a BuildKit secret, never into an image; LINORA_BUILD_CA sets it for the build alone. If pulling base images fails with x509: certificate signed by unknown authority, Docker itself needs the CA: add it to the system’s trusted certificates and restart Docker. | | The build stops with exit code: 137 or Killed, a tier keeps restarting in npm run prod:ps, or prod-up ends with is unhealthy or dependency failed to start | Usually too little memory for Docker. Give it at least 4 GB (Docker Desktop: Settings > Resources; WSL: .wslconfig) and run npm run prod:up again. docker inspect -f '{{.State.OOMKilled}}' <project>-<service>-1 confirms an out-of-memory kill; npm run prod:logs -- <service> shows the rest. Idle, the whole stack uses about 300 MB. The mem_limit values in docker-compose.prod.yml are caps, not reservations; only the large-page compactor can approach its 4 GB, while it compacts a very large page. | | npm ci warns EBADENGINE with required: { node: '>=26.4.0' }, prod-up says Node ... is too old, or npm run prod:env prints nothing | Node is older than 26.4. Install a newer one (nvm install 26), check node --version, and start again from npm ci. | | prod-up: git rev-parse ...: not a git repository | prod-up builds a committed revision, so it needs a git clone, not a downloaded source archive. | | smoke: FAIL signup with 403 | Sign-up is invite-only: add @example.com to LINORA_PROD_SIGNUP_ALLOWLIST while you run the smoke test. | | Another device can’t open the app | The stack listens on 127.0.0.1 only until you turn on LAN mode. |

Output that looks alarming but is fine:

Reset a throwaway install. This deletes all of its data:

npm run prod:down -- -v        # containers, networks and volumes
npm run prod:env -- --force    # new secrets; the old .env.prod is backed up next to it
npm run prod:up

--force writes default settings, so copy LINORA_PROD_PORT, LINORA_PROD_LAN_HOSTS, LINORA_PROD_EDGE_SUBNET or the sign-up settings over from the backup before prod:up. To remove Linora completely, run npm run prod:down -- -v --rmi local and delete the clone.