One file to upload#
deploy writes a small entry file that imports every api file, registers each export under its endpoint id and starts the ArkAPI server. Bun.build turns that into one JavaScript file (cli/src/bundle.ts). Nothing changes until it builds and the upload succeeds: no app is created and the client is not pointed at the cloud before that.
Swapping the server under a live chat#
The host (host apps.ts, server.ts) never stops the old version first:
time ─────────────────────────────────────────────────────►
v3 ██████████████████████████████████▌ stopped
v4 ░░ starting ░░░░█████████████████████████
▲
│ v4 answers: traffic moves to v4
phone ══════════════════════════╪════════════════════════
socket (never closed) └ host attaches it to v4
and replays its subscriptions
- The bundle is stored as a new version and started on a free port, next to the running one.
- Only when it answers does the host mark it active and send traffic to it.
- Phones never connect to your backend directly; they connect to the host, which forwards. When the old version goes away, the host keeps the phone's socket open, connects it to the new version and replays every subscription that phone had open. The screen keeps updating as if nothing happened.
- A version that fails to start changes nothing. Rollback re-activates an older stored version the same way.
When the backend falls over#
- A version that exits is restarted after a second. Open sockets wait for it, up to about 6 seconds.
- A request that has not started answering after 5 seconds gets
504, and the stuck process is restarted. - Five exits within a minute pause the app instead of looping forever; the dashboard says why. Redeploy or roll back to resume.
Jobs never run twice#
During a deploy two versions run side by side, and both loaded your every('1h', ...). Each version knows its own id; before a job runs it checks the app's .active marker and skips if it is not the active one. A run still going when the next is due is skipped too. Intervals are aligned to the clock, so every('1h') fires on the hour, and live data refreshes after each run.
Each app in its own box#
Apps are started through a small root-owned launcher (host deploy/runner.ts) as their own systemd units:
- Own user and directory. The process can write only to its app directory (
ProtectSystem=strict,ReadWritePaths), cannot gain privileges, has no capabilities and its own/tmp. - Own budget. 0.5 CPU core, 256 MiB memory, no swap, 64 tasks. One app spinning in a loop cannot slow down another.
- Clean environment. Only
PORT,PATH,HOME, the version id and your own variables. - Logs that cannot fill the disk. Each log is cut down to its last 256 KB once it passes 1 MB.