Skip to main content
OASM is built so that every component except the data stores can run as several copies. This page explains what holds state, how replicas of the core API coordinate, and what an operator has to size. For the deployment steps, see Deployment and Worker.

Where state lives

Scaling the core API

The core API is stateless in the durable sense, so it scales by adding replicas behind a load balancer. Three patterns make that safe.

Broadcast, holder acts

Some state is necessarily per process: a worker’s gRPC streams and a browser’s SSE connection are open to exactly one replica. When another replica needs to reach them — to cancel a job, to hint that new jobs are waiting, to deliver an AI agent command’s output — it publishes on a Redis channel, every replica receives it, and only the replica that holds the stream acts. No replica needs to know where a worker is connected.

Exactly-once background work

Cron jobs — retention, cleanup, rollups, the daily statistics snapshot, risk-acceptance expiry, the workflow-run reconciler — run on every replica’s scheduler, but each one is wrapped in a Redis lock with a TTL. The first replica to take the lock does the work; the others skip that tick. The same applies to boot tasks such as connector sync and key rotation. Scheduled scans and project schedules are BullMQ jobs, which Redis already delivers once. A few tasks need no lock because they are idempotent. The stale-worker sweep runs on every replica: deleting a worker that has no heartbeat, and re-queueing its jobs, gives the same result however many times it runs.

The database decides

Where two replicas might race, the database arbitrates rather than an in-memory lock:
  • Claiming uses FOR UPDATE SKIP LOCKED, so two workers on two replicas never get the same job. See Claiming.
  • Terminal states are conditional updates (WHERE status = 'IN_PROGRESS'), so a cancel and a result arriving together resolve cleanly.
  • Advancing a run locks the run row and only happens when a step has drained, which every replica can check from committed data. See Advancing a run.
  • Quotas and issue numbers are single conditional statements or row locks, never read-then-write.

Scaling workers

Workers pull work, so adding capacity is adding workers. Each worker sizes its own slots from the CPU and memory it can see, claims only as many jobs as it has free slots, and keeps its own identity even when several replicas share one host or one state volume. A queue that grows is always an execution-layer signal — not enough connected capacity — because jobs never time out of the queue. See Capacity and scaling. To scan from several networks, run workers in each network and attach them to an internal network, or scope them to the workspace that owns those targets.

Sizing

Failure modes

  • A core API replica dies. Its workers reconnect to another replica and resume with their tokens; their running jobs are not lost. Browsers reconnect their event stream. Jobs whose results were staged but not processed stay in the queue.
  • A worker dies. After 60 seconds without a heartbeat it is removed and its jobs return to the queue for another worker.
  • Redis restarts. Sessions are re-read from the database, schedules are re-registered when the API starts, and locks expire on their own. Worker gRPC streams do not go through Redis and stay up.
  • PostgreSQL is unavailable. The platform cannot make progress until it returns, because every state change is recorded there first.

Job registry

Claims, results and recovery in detail

Worker and connector runtime

Worker identity, channels and capacity

Event bridge

Delivery guarantees of the event stream

Deployment

Run the stack and scale workers