Linora

Server build, images and their footprint

How the server tiers are built for production, what that saves, and how to reproduce the numbers. Decisions: ADR 0902 (compiled JS) and ADR 0903 (images). Deployment: deploy.md.

Compiled JS for the servers

Dev and tests run TypeScript directly (Node 26 strips types, ADR 0001). Production does not: the stripper is a WebAssembly module that every isolate (the main thread and each worker thread) instantiates on its first .ts file. An empty script costs 49 MiB RSS as .js and 77 MiB as .ts.

npm run build:server (deploy/build.mjs, ~0.25 s, no new dependency):

  1. tsc -p tsconfig.build.json (TypeScript 7, emit only; npm run typecheck does the checking). Inputs are the src/ dirs of the server closure: shared, packages/{doc,sync-client,server-common}, apps/{api,realtime,docworker,mcp}. rewriteRelativeImportExtensions turns ./x.ts imports into ./x.js; the target is ESNext, so nothing is downlevelled, and comments are dropped (less source text kept in memory).
  2. new URL('./worker.ts', import.meta.url) worker entry points are URLs, not imports, so the script rewrites them to .js and checks that the target exists.
  3. Every relative import in the output must exist, and no specifier may still end in .ts.
  4. dist/<workspace>/package.json: the manifest with exports pointing at .js, no scripts or devDependencies. dist/node_modules/@linorahq/* are relative links to the compiled packages, so they shadow the repo’s links to src/.
  5. Runtime files read by path are copied: db/migrations (the migrate runner) and packages/doc/assets/fonts (resvg render).

dist/ mirrors the repo layout, so paths relative to a module resolve unchanged. Third-party packages resolve from the nearest node_modules above dist/: the repo’s locally, /app/node_modules in an image. Start scripts: npm run start:api|start:realtime|start:docworker|start:compactor|start:mcp. They run with --no-strip-types, so a stray .ts fails at startup instead of silently costing ~25 MiB per isolate.

RSS saved

deploy/measure-rss.mjs starts each server from src/ and from dist/, alternating ABBA across runs on private ports against a scratch database. It samples RSS (median of 5) after 3 s idle (idle), and again after 300 light requests (warm). Values are medians of 3 runs, in MiB.

Linux (Docker Desktop VM, arm64, Node 26.4.0, 4 CPUs; realtime at its Linux default of 5 gateway + 2 owner threads):

Server src idle dist idle saved src warm dist warm saved
api 107.0 68.4 38.6 (-36%) 109.2 71.9 37.3 (-34%)
realtime (5 gw + 2 owners) 330.3 196.0 134.3 (-41%) 335.9 207.7 128.2 (-38%)
realtime (1 gw + 2 owners) 201.6 124.9 76.7 (-38%) 206.2 137.1 69.0 (-33%)
docworker 107.3 69.3 38.0 (-35%) 110.2 73.7 36.5 (-33%)
compactor 107.8 69.7 38.0 (-35%) 109.8 73.5 36.2 (-33%)
mcp 118.6 87.5 31.1 (-26%) 118.7 87.9 30.8 (-26%)

macOS (M4 Pro, Node 26.4.0; realtime defaults to 1 gateway on macOS):

Server src idle dist idle saved src warm dist warm saved
api 124.9 77.7 47.3 (-38%) 128.4 82.2 46.2 (-36%)
realtime (1 gw + 2 owners) 251.2 146.1 105.1 (-42%) 257.5 158.8 98.8 (-38%)
realtime (5 gw + 2 owners) 405.3 273.2 132.1 (-33%) 412.0 288.0 124.0 (-30%)
docworker 135.1 80.5 54.5 (-40%) 138.4 85.0 53.3 (-39%)
compactor 132.4 80.8 51.7 (-39%) 135.3 86.0 49.3 (-36%)
mcp 137.7 90.7 47.0 (-34%) 141.6 91.7 49.9 (-35%)

Realtime saves the most because every gateway and owner thread is its own isolate. In the production image (distroless, Node 26.13), the API sits at 69.5 MiB idle, down from 126 MiB measured under .ts in wave 1.

Reproduce: npm run build:server, create a scratch database, then DATABASE_URL=postgres://linora:linora@localhost:5432/<scratch> node --env-file-if-exists=.env deploy/measure-rss.mjs --runs 3 [--only api,realtime] [--json out.json]. For Linux numbers, run it inside the build-server stage of deploy/Dockerfile (it reads /proc there).

Images

One multi-target deploy/Dockerfile (ADR 0903). Measured 2026-11-28 on arm64:

Image Base Our layers Compressed (pull)
api distroless nodejs26-debian13 (254 MB unpacked) dist 2.5 MB + node_modules 1 MB (postgres) 60.6 MB
realtime same + 7.3 MB (postgres, uWS for this platform and ABI only) 63.1 MB
docworker (worker + compactor) same + ~6 MB (postgres, resvg for this platform) 62.6 MB
mcp same + ~17 MB (MCP SDK and its dependencies) 62.2 MB
web nginx-unprivileged 1.29 alpine Vite build, precompressed 23.5 MB

The four server images share their base layers, so a host pulls the base once (~58 MB) plus a few MB per tier. Pruned from each tier’s node_modules: type declarations, source maps, markdown, and uWS binaries for other platforms and ABIs (90 MB -> 7 MB).