Skip to Content

Compute Worker

Run the compute worker as its own service, for Vercel or a dedicated compute host.

The compute worker generates speech, analyzes PDFs, makes previews and exports, and serves audio to browsers. Docker, source installs and the desktop app run it for you.

Run it separately on Vercel, where it cannot run inside the app, or to use a dedicated host. Deploy the same version as the app:

ghcr.io/richardr1126/openreader-compute-worker:latest

What it needs

RequirementDetails
NATS JetStreamThe job queue, with file storage. Only the worker connects to it.
S3-compatible storageThe same bucket as the app. The embedded SeaweedFS cannot be shared.
HTTPS to the appFor provider keys, limits and account email settings. Plain HTTP works only on the same host.
A public addressBrowsers load audio from it. HTTPS if the app is.
Access to your TTS providersThe worker makes the speech requests.

The worker never connects to the database and never receives AUTH_SECRET.

Shared values

Generate each once (for example with openssl rand -base64 32) and set the same value on both the app and the worker:

VariableUsed for
COMPUTE_WORKER_TOKENThe app's requests to the worker.
COMPUTE_CREDENTIAL_BROKER_TOKENThe worker's requests to the app.
TTS_PLAYBACK_TOKEN_SECRETSigning the short-lived audio and reader links browsers use.

None of them is ever sent to browsers.

Worker settings

COMPUTE_WORKER_TOKEN=<shared>
COMPUTE_CREDENTIAL_BROKER_URL=https://reader.example.com/api/internal/compute/tts-credentials
COMPUTE_CREDENTIAL_BROKER_TOKEN=<shared>
TTS_PLAYBACK_TOKEN_SECRET=<shared>

NATS_URL=nats://nats.example.com:4222
# NATS_CREDS=<contents of a .creds file>, or NATS_CREDS_FILE=/path/to/user.creds

S3_BUCKET=<same as the app>
S3_REGION=<same as the app>
S3_ACCESS_KEY_ID=<same as the app>
S3_SECRET_ACCESS_KEY=<same as the app>
S3_INTERNAL_ENDPOINT=<the same storage, at an address the worker can reach>
# S3_FORCE_PATH_STYLE and S3_PREFIX: same as the app

LOG_FORMAT=json
COMPUTE_LOG_LEVEL=info

The worker listens on PORT (default 8081), which most platforms set for you. The rest rarely needs changing; see Environment Variables.

App settings

COMPUTE_WORKER_URL=https://worker.example.com
COMPUTE_WORKER_TOKEN=<shared>
COMPUTE_CREDENTIAL_BROKER_TOKEN=<shared>
TTS_PLAYBACK_TOKEN_SECRET=<shared>
# Only if browsers reach the worker at a different address:
# COMPUTE_WORKER_PUBLIC_URL=https://worker-public.example.com

With COMPUTE_WORKER_URL set, the app does not start its own worker. If this one is down, playback and document processing fail until it is back.

If the app is on HTTPS, the worker's public address must be too, or browsers block the audio.

Railway

Create NATS

Use the official nats:alpine image, with a volume at /data and public networking off. Its configuration needs JetStream with store_dir: "/data", so queued work stays on the volume, and listen: "[::]:4222", for Railway's IPv6 private network.

To supply it, base64-encode the configuration into a service variable named NATS_CONFIG_B64 and set this start command:

/bin/sh -c "echo $NATS_CONFIG_B64 | base64 -d > /tmp/nats.conf && exec nats-server -c /tmp/nats.conf"

Create the worker

Create a service from the worker image in the same project and environment, with public networking on.

Set its variables

Use the worker settings, with NATS_URL at the NATS private address, such as nats://nats.railway.internal:4222. If NATS uses JWT authentication, put a user's .creds contents in NATS_CREDS.

Point the app at it

Set COMPUTE_WORKER_URL=https://<railway-worker-domain> on the app.

Let the worker sleep

Set COMPUTE_NATS_DISCONNECT_WHEN_IDLE=true. The worker disconnects after two idle minutes and reconnects on the next request. Keep at least one worker connected if jobs must recover without a request.

NATS cluster

A cluster keeps queued work when one server is lost.

  1. Run at least three servers, each its own service with its own empty volume.
  2. Give each a unique server_name, and all of them the same cluster block: one cluster name, listen: "[::]:6222", and routes to every server's private address.
  3. List their client addresses in NATS_URL, separated by commas, and set COMPUTE_NATS_REPLICAS=3 on the worker.

Health checks

PathResponse
GET /health/live{ "ok": true } while the process runs.
GET /health/readyAdds natsConnected. The status is 200 either way.

After deploying, open Settings → Admin → Maintenance in the app. The system check confirms the app can reach the worker and that your browser can load its audio.

On this page

Edit this page