A distributed service mesh that turns Postgres into a durable workflow orchestration engine. Every HotMesh.init() call creates a point of presence — an engine, a quorum member, and zero or more workers — that collaborates with its peers through Postgres LISTEN/NOTIFY to form a self-coordinating mesh with no external dependencies.

Each HotMesh instance joins a quorum — a real-time pub/sub channel backed by Postgres LISTEN/NOTIFY. The quorum is the mesh's nervous system: version activations, throttle commands, roll calls, and custom user messages all propagate instantly to every connected engine and worker across all processes and servers.

import { HotMesh } from '@hotmeshio/hotmesh';
import { Client as Postgres } from 'pg';

const hotMesh = await HotMesh.init({
appId: 'myapp',
engine: {
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' },
},
},
workers: [{
topic: 'order.process',
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' },
},
callback: async (data) => ({
metadata: { ...data.metadata },
data: { orderId: data.data.id, status: 'fulfilled' },
}),
}],
});

// Deploy a YAML workflow graph
await hotMesh.deploy(`
app:
id: myapp
version: '1'
graphs:
- subscribes: order.placed
publishes: order.fulfilled
expire: 600

activities:
t1:
type: trigger
process:
type: worker
topic: order.process
input:
schema:
type: object
properties:
id: { type: string }
maps:
id: '{t1.output.data.id}'
transitions:
t1:
- to: process
`);

await hotMesh.activate('1');

// Fire-and-forget
const jobId = await hotMesh.pub('order.placed', { id: 'ORD-123' });

// Request/response (blocks until workflow completes)
const result = await hotMesh.pubsub('order.placed', { id: 'ORD-456' });
  1. init — Create an engine + workers; join the quorum.
  2. deploy — Upload a YAML graph to Postgres (inactive).
  3. activate — Coordinate the quorum to switch to the new version.
  4. pub / pubsub — Trigger workflow execution.
  5. stop — Leave the quorum and release connections.

For most use cases, prefer the higher-level wrappers:

  • Durable — Durable workflow functions with replay and retry.
  • Virtual — Virtual network functions and idempotent RPC.

Properties

appId: string
guid: string
logger: ILogger
namespace: string
disconnecting: boolean = false
listWorkerRoles: ((config: {
    connection: ProviderConfig | ProvidersConfig;
    namespace?: string;
}) => Promise<WorkerCredentialInfo[]>) = WorkerCredentials.listWorkerRoles

List all provisioned secured worker roles.

Type declaration

provisionWorkerRole: ((config: {
    connection: ProviderConfig | ProvidersConfig;
    namespace?: string;
    password?: string;
    streamNames: string[];
}) => Promise<WorkerCredential>) = WorkerCredentials.provisionWorkerRole

Provision a scoped Postgres role for a worker. The role can only dequeue, ack, and respond on its assigned stream names via stored procedures — zero direct table access.

Type declaration

    • (config): Promise<WorkerCredential>
    • Provision a scoped Postgres role for a worker router.

      The role can only dequeue/ack/respond on the specified stream names via SECURITY DEFINER stored procedures — it has zero direct table access.

      Parameters

      Returns Promise<WorkerCredential>

revokeWorkerRole: ((config: {
    connection: ProviderConfig | ProvidersConfig;
    namespace?: string;
    roleName: string;
}) => Promise<void>) = WorkerCredentials.revokeWorkerRole

Revoke a secured worker role (disables login).

Type declaration

    • (config): Promise<void>
    • Revoke a worker role by disabling login. The role is not dropped, preserving the audit trail in the worker_credentials table.

      Parameters

      Returns Promise<void>

rotateWorkerPassword: ((config: {
    connection: ProviderConfig | ProvidersConfig;
    namespace?: string;
    newPassword?: string;
    roleName: string;
}) => Promise<{
    password: string;
}>) = WorkerCredentials.rotateWorkerPassword

Rotate a secured worker role's password.

Type declaration

    • (config): Promise<{
          password: string;
      }>
    • Rotate the password for an existing worker role.

      Parameters

      Returns Promise<{
          password: string;
      }>

Methods

  • Activates a previously deployed version across all connected instances. The quorum coordinates a synchronized version switch so every engine and worker transitions together.

    Parameters

    • version: string

      The version string to activate (must match a deployed graph).

    • Optionaldelay: number

      Optional delay in ms before activation takes effect.

    Returns Promise<boolean>

  • Requests cooperative cancellation of a running job. Sets a durable cancel flag; the workflow detects it at its next durable operation and throws CancelledFailure, which can be caught for cleanup.

    Parameters

    • jobId: string

      The job/workflow ID.

    Returns Promise<void>

  • Deploys a YAML workflow graph to Postgres. The graph is stored but remains inactive until activate is called.

    Parameters

    • pathOrYAML: string

      A file path or raw YAML string defining the workflow graph.

    Returns Promise<HotMeshManifest>

    The parsed manifest with version and graph metadata.

  • Exports the full job state (data, metadata, activity results) as a structured JSON object.

    Parameters

    • jobId: string

      The job/workflow ID.

    • options: ExportOptions = {}

      Export options (e.g., include activity details).

    Returns Promise<JobExport>

  • Returns the structured job state (data + metadata). For a completed job this is the final output; for a running job it reflects the latest persisted state.

    Parameters

    • topic: string

      The workflow topic.

    • jobId: string

      The job/workflow ID.

    Returns Promise<JobOutput>

  • Returns the numeric status code for a job: 0 = completed, positive = still running, negative = interrupted/errored.

    Parameters

    • jobId: string

    Returns Promise<number>

  • Immediately terminates a running job. The job is marked as interrupted and its HASH is expired. Unlike cancel, this does not give the workflow a chance to run cleanup code.

    Parameters

    • topic: string

      The workflow topic.

    • jobId: string

      The job/workflow ID.

    • options: JobInterruptOptions = {}

      Optional interrupt configuration.

    Returns Promise<string>

  • Subscribes to workflow emissions matching a wildcard pattern.

    Parameters

    • wild: string

      The wildcard pattern (e.g., 'order.*').

    • callback: JobMessageCallback

      Invoked with each matching emission.

    Returns Promise<void>

  • Publishes a message to a workflow topic, starting a new job. Returns the job ID immediately (fire-and-forget).

    Parameters

    • topic: string

      The workflow topic (must match a deployed graph's subscribes).

    • data: JobData = {}

      Input data for the workflow.

    • Optionalcontext: JobState
    • Optionalextended: ExtensionType

    Returns Promise<string>

    The new job ID.

  • Publishes a custom message to every instance via the quorum channel. Register a listener with subQuorum to receive these messages.

    Parameters

    Returns Promise<boolean>

  • Publishes a message and blocks until the workflow completes, returning the final job output. Combines pub + sub into a single request/response call.

    Parameters

    • topic: string

      The workflow topic.

    • data: JobData = {}

      Input data for the workflow.

    • Optionalcontext: JobState

      Optional job state context.

    • Optionaltimeout: number

      Optional timeout in milliseconds.

    Returns Promise<JobOutput>

    The completed job output.

  • Unsubscribes from a wildcard pattern previously registered with psub.

    Parameters

    • wild: string

    Returns Promise<void>

  • Broadcasts a PING to all connected engines and workers via LISTEN/NOTIFY and collects their profiles. Returns one QuorumProfile per responding instance, including cumulative message counts, error_count, stream_depth, throttle state, and host-level system health (memory/CPU).

    Use this for health checks, topology discovery, and throughput monitoring across the mesh.

    Parameters

    • Optionaldelay: number

      Time in ms to wait for PONG responses (default: quorum config).

    Returns Promise<QuorumProfile[]>

    One profile per responding engine/worker instance.

  • Immediately deletes a completed job's HASH record from Postgres.

    Parameters

    • jobId: string

    Returns Promise<void>

  • Sends a signal to a paused workflow, delivering data and resuming execution. Pairs with condition() in the Durable workflow API.

    Parameters

    • topic: string

      The signal topic.

    • data: JobData

      Signal payload.

    • Optionalstatus: StreamStatus
    • Optionalcode: number

    Returns Promise<string>

  • Stops this specific HotMesh instance — leaves the quorum and stops all workers. Does not affect other instances in the process.

    Returns void

  • Subscribes to all output and interim emissions from a workflow topic.

    Parameters

    • topic: string

      The topic to subscribe to.

    • callback: JobMessageCallback

      Invoked with each job output or interim emission.

    Returns Promise<void>

  • Subscribes to the quorum channel to receive system messages (version activations, throttle commands, roll calls) and custom user messages.

    Parameters

    Returns Promise<void>

  • Broadcasts a throttle command to all instances. Use to slow down or pause message consumption across the mesh.

    Parameters

    • options: ThrottleOptions

      Throttle rate in ms (0 = no throttle, -1 = pause indefinitely). Optionally scope by guid (single instance) or topic (single worker).

    Returns Promise<boolean>

  • Unsubscribes from a workflow topic previously registered with sub.

    Parameters

    • topic: string

    Returns Promise<void>

  • Generates a unique ID using the same nanoid generator used internally by HotMesh for job IDs and GUIDs.

    Returns string

  • Create a HotMesh instance with an engine and optional workers.

    The engine manages workflow state in Postgres. Workers are callback functions that consume messages from Postgres streams — they can run on the same process or on entirely separate servers.

    Parameters

    • config: HotMeshConfig

      Engine connection, worker definitions, app ID, and options.

    Returns Promise<HotMesh>

    A running HotMesh instance joined to the quorum.

  • Register a global payload codec for encoding/decoding serialized object data at rest. Once registered, all object values flowing through the serializer are stored as /b{encoded} instead of /s{json}. Use this for encryption, compression, or custom encoding.

    The codec is global — it applies to all HotMesh and Durable instances in the process. Pass null to remove a previously registered codec.

    Constraints: The codec must be synchronous and its output must be a valid UTF-8 string. Use base64 encoding for binary output.

    Parameters

    Returns void

    import { HotMesh } from '@hotmeshio/hotmesh';

    HotMesh.registerCodec({
    encode(json) { return Buffer.from(json).toString('base64'); },
    decode(encoded) { return Buffer.from(encoded, 'base64').toString('utf8'); },
    });