Architecture

World Composition

Configure worker world implementations for remote execution

Overview

worker.world is the runtime world input for worker boot.

You can configure it as:

  • a world factory that returns a complete World, or
  • a composed object with base and optional queue/streams primitives.

World factory

Use this when you already have a complete world implementation.

import { defineWorkflowStudioConfig } from 'workflow-studio';
import { createWorld } from '@workflow/world-postgres';

export default defineWorkflowStudioConfig({
  worker: {
    world: ({ env }) =>
      createWorld({
        connectionString: env.WORKFLOW_POSTGRES_URL!,
      }),
  },
});

Composed world primitives

Use this when you are composing storage, queue, and stream primitives.

import { defineWorkflowStudioConfig } from 'workflow-studio';

export default defineWorkflowStudioConfig({
  worker: {
    world: {
      base: ({ env }) => createStorageBase({ url: env.DB_URL! }),
      queue: ({ env }) => createQueuePrimitive({ token: env.QUEUE_TOKEN! }),
      streams: ({ env }) => createStreamPrimitive({ key: env.STREAM_KEY! }),
    },
  },
});

Required methods in composed mode

base must provide:

  • runs
  • steps
  • events
  • hooks

Queue methods must resolve from queue(...) or fallback from base:

  • getDeploymentId
  • queue
  • createQueueHandler

Stream methods must resolve from streams(...) or fallback from base:

  • writeToStream
  • closeStream
  • readFromStream
  • listStreamsByRunId

Optional pass-through methods:

  • writeToStreamMulti
  • start
  • close
  • getEncryptionKeyForRun

Factory context

World and primitive factories receive:

type WorkerFactoryContext = {
  env: NodeJS.ProcessEnv;
  cwd: string;
};

This supports provider-specific credentials and community world setup.

Failure behavior

Worker startup fails fast when:

  • worker.world is missing,
  • composed mode is missing base,
  • required storage/queue/stream methods are missing.

Use workflow-studio worker check-config before deployment.