Skip to content
MSO CloudDocumentation

Worker components

On this page

Level: C4 L3, components of the worker container. Read this if you are an engineer adding a job, tuning a queue or deciding how workers are split across processes.

Up/Down: up: L2 Containers. Siblings: Web app components. Domain flow of the data these jobs move: Ingest pipeline.

In short#

One worker image runs BullMQ consumers over Redis. A WORKER_POOL setting picks which queue groups a process starts; by default one process starts all of them. Producers write durable intent to a Postgres outbox, a dispatcher publishes it, and one wrapper classifies every failure.

C4 level 3: worker components from outbox and schedulers through queues and pools to packages

Components#

Component Where Owns
Queue definitions apps/worker/src/queues.ts Queue names (a stable contract: renaming orphans in-flight jobs), Zod payload schemas, retry options
Pools apps/worker/src/pool.ts, index.ts sync, ai, alerts, materialize, scheduled, archive, all; each worker registration is tagged with one
Outbox dispatcher apps/worker/src/job-outbox-dispatcher.ts Claims committed outbox rows with FOR UPDATE SKIP LOCKED, publishes with a stable job id, marks them
Schedulers apps/worker/src/schedules.ts, playbook-scheduler.ts Cron-style jobs upserted by stable id at boot, patterns pinned to Vietnam time
Processors apps/worker/src/processors One file per job family: connector sync (marketplace, marketing, dataset), webhooks, AI, alerts, notify delivery, rollups, backups
Failure wrapper job-failure-wrapper.ts, job-failure-classifier.ts One classification for every worker: permanent, transient or parked
Watchdog apps/worker/src/watchdog A separate process from the same image; evaluates alarms over web and worker metrics

Pools#

Pool Runs
sync Per-marketplace, marketing and file sync queues, marketplace webhooks, OAuth token refresh
ai Model-bound jobs
alerts Alert evaluation, notification delivery, briefings, audience refresh
materialize Gold rollups, action memos, playbook runs, manual uploads, dashboard subscriptions, dataset and validation jobs
scheduled The cron dispatcher, the outbox dispatcher and the minute sweep that delivers platform webhooks
archive Organization backup and restore, under its own database identity

Rollup rebuilds of one organization are serialized by a transaction-scoped Postgres advisory lock (packages/metrics/src/rollup-lock.ts), so two worker processes cannot interleave a rebuild. The scheduled pool should still run in exactly one process: scheduler upserts are idempotent, but the outbox dispatcher and sweeps are cheaper to reason about with one owner.

Durable handoff and failure handling#

A web change that needs async work writes an outbox row in the same transaction, so the change and the intent commit or roll back together. The dispatcher publishes after commit; the job id makes a crash between publish and mark replay-safe.

Failure Class Effect
Unprocessable payload, authentication, decrypt or template error, constraint violation, client error other than timeout or rate limit Permanent One dead-letter row; retries stop
Vendor rate limit Parked The connector cools down and shows as degraded; no alert
Anything else Transient Retry with exponential backoff and jitter (sync queues: 5 attempts from 30 s)

Connector sync, step by step#

Dynamic view: a connector sync from scheduler through queue, processor, Bronze, Silver and Gold to briefs and alerts

The same flow, with the tables and guarantees at each step, is in Ingest pipeline.

Alert delivery#

The alerts pool evaluates rules over Gold, writes incidents and enqueues notification jobs. A message leaves only when platform, organization and person all allow the channel; the in-app inbox needs no transport. Transport failures use the same permanent, transient and unsubscribe classes. See Notifications.

Where it stops#

Pool splitting is supported by the code and by an optional compose overlay, but the overlay is not the default deployment; see Deployment. Readiness per capability: Project status.