Docs / Self-hosting

Scaling the worker

Run background jobs in a separate process when they slow the web app.

Overview

Datum runs matching, profile rebuilds, Slack routing, sink deliveries, event publishing, backups and retention tasks in the background. A Postgres job queue stores this work. A worker process executes the jobs.

The standard Compose stack runs the worker inside the app container with serve --embedded-worker. This configuration needs two containers and one database. It is sufficient for most communities.

When to split it out

Run a separate worker when background jobs slow the web app. This can happen during a large initial import.

Matching processes queued jobs as quickly as possible. An embedded worker shares the server’s database connections with page requests. Pages can wait for those connections. A separate worker uses its own connections.

Configure

Run a separate worker on Compose

Exactly one process should configure the queue at startup. A separate worker therefore replaces the embedded worker.

  1. Add a second Compose file

    Save the following configuration as deploy/compose.worker.yml.

    services:
      app:
        command: ["serve", "--port", "3000", "--host", "0.0.0.0"]
      worker:
        image: ${OCMGR_IMAGE:-ocmgr:local}
        restart: unless-stopped
        env_file:
          - path: .env
            required: false
        environment:
          OCMGR_DATA_DIR: /data
        command: ["worker"]
        stop_grace_period: 45s
        healthcheck:
          disable: true
        volumes:
          - data:/data
        depends_on:
          app:
            condition: service_healthy

    This removes --embedded-worker from the app. It adds a worker with the same image, settings and data volume. The worker serves no web pages, so the configuration disables its web health check.

  2. Start with both files

    Include both files in every command that starts the stack.

    docker compose -f deploy/docker-compose.yml -f deploy/compose.worker.yml up -d
  3. Check the worker

    Wait for the worker’s first check-in, which takes up to five minutes. Inspect the job status.

    docker compose -f deploy/docker-compose.yml -f deploy/compose.worker.yml \
      exec -T app ocmgr jobs status --json

    The status should show a live worker that processes queued jobs.

The worker needs the data volume to write nightly and hourly backups to /data/backups.

Partitions

The --queues option selects which jobs a worker processes.

Option Jobs
--queues all All jobs. This is the default and the embedded worker’s setting.
--queues core Matching, profiles, routing, events, backups, retention and other core jobs.
--queues pieces Reviewed Activepieces sources and sinks, such as HubSpot, Zoom and Google Sheets.

The hosted service separates core and pieces workers so third-party pieces cannot access core credentials. A self-hosted installation can use one all worker unless it needs the same separation.

Basics

Check the worker is alive

Each partition records a check-in every five minutes. Backfills from the app or an agent require a check-in from the relevant partition within the previous 15 minutes.

Inspect the worker status and completed check-ins.

docker compose -f deploy/docker-compose.yml exec -T app ocmgr jobs status --json
docker compose -f deploy/docker-compose.yml exec -T app ocmgr jobs ls --queue system.canary --state completed --json

Use --queue piece.canary for the pieces partition. Wait for the first check-in before retrying a backfill that reports no worker.

Database connections

The server permits up to 10 database connections by default, including the embedded worker. A standalone worker permits up to 4. OCMGR_DB_POOL_SIZE changes these limits. The queue and sign-in services use additional small connection pools.

Allow for all processes when you configure Postgres capacity.

From your terminal or agent

Read worker status with an admin API key or an admin connection to hosted MCP. The operator terminal needs database access.

ocmgr jobs status --json

Queue totals and backup status describe the whole instance. Connection identifiers are limited to your workspace. The report contains no individual job payloads. Check canaryAgeSeconds for the core worker and piecesCanaryAgeSeconds for the pieces worker. null means that worker has never completed a check-in.

queue_failing warns when unresolved dead letters are older than 24 hours, even with fresh worker check-ins. reasons includes their total count and oldest age in seconds. Recent repeated failures or late check-ins can also produce this warning. A stopped worker still produces the stronger queue_stuck status. The warning does not trigger the stuck-worker alert: /healthz?deep=1 remains HTTP 200 and includes the warning in its body.

Read queue.deadLettersByQueue to separate failures by their original queue:

Field Meaning
queue Original queue name, or null for an older job that did not record one.
total Unresolved dead letters from that queue.
last24Hours Of that total, how many entered the dead-letter queue in the last 24 hours.
oldestSeconds Age of the oldest unresolved dead letter, in seconds since it entered the dead-letter queue.
connections The same counts and age for each connection explicitly named by a job in your workspace.

Match each connections[].connectionId to connections[].id in the report’s top-level list to find the source or connection’s name and kind. The terminal’s text output also prints the name when available. A removed connection may have only an ID.

Jobs without an explicit connection ID, including system jobs, remain in the queue totals. So do jobs from other workspaces, whose identifiers are withheld. Connection counts can therefore add up to less than the queue total. This breakdown does not include dead letters that you retried or purged. Public deep health includes queue totals but no connection IDs.

Only the operator can inspect individual jobs with ocmgr jobs ls --dead --json. Hosted workspace owners should ask the operator to investigate. See Backups and restore to interpret the backup fields.

FAQ

Can I run two workers for more throughput?

The supplied configurations run one worker per partition. Matching already processes queued jobs as quickly as possible.

Separate busy piece sources into a pieces worker alongside a core worker. Retain only one worker for pieces while you use a Google Sheets sink.

What if no worker is running at all?

Terminal commands can still complete their work synchronously, such as ocmgr ingest followed by ocmgr match. The app and agents reject backfills until a worker checks in. Routing, sinks, events and backups wait for a worker.

Do I need to restart the worker after changing settings?

Yes. Each process reads deploy/.env at startup. Recreate both processes with up -d.