pg-workflows

Introduction

Durable workflows for TypeScript, backed by PostgreSQL.

pg-workflows runs durable workflows on the PostgreSQL you already have. Each step's result is saved, a retried run skips the steps that already finished, and a run can pause for an event, a timer, or a polled condition. There's no Redis, broker, or scheduler to run.

Prompt for your coding agent

Add pg-workflows to this project. Fetch https://pgworkflows.dev/skill.md and follow it step by step: pick the right layout for this codebase (monolith, web app plus worker, or microservices), install and verify the engine, add the @pg-workflows/ui dashboard for our stack, then ask me whether to add OpenTelemetry tracing.

Start here

Features

FeatureAPI
Durable stepsstep.run(id, fn)
Wait for external eventsstep.waitFor(id, { eventName, timeout?, schema? }) + engine.triggerEvent()
Timersstep.delay(id, '3 days'), step.waitUntil(id, date)
Pollingstep.poll(id, fn, { interval, timeout })
Manual pause and resumestep.pause(id), engine.resumeWorkflow()
Child workflowsstep.invokeChildWorkflow(id, ref, input)
Recurring schedulesworkflow(id, fn, { schedule: '0 9 * * 1-5' })
Retriesworkflow(id, fn, { retries: 3 })
Prioritiesworkflow(id, fn, { priority: 'high' })
One run at a timeworkflow(id, fn, { singleton: true })
Deduplicated startsstartWorkflow({ idempotencyKey })
Tenant scopingresourceId on every run and every API call
Typed inputAny Standard Schema library (Zod, Valibot, ArkType)
Microservices (web and worker)WorkflowClient from pg-workflows/client

Packages

PackagePurpose
pg-workflowsThe engine and client
@pg-workflows/uiReact dashboard, components, and hooks. Try it with npx @pg-workflows/ui
@pg-workflows/otelOpenTelemetry spans for workflow runs and steps

Requirements

  • Node.js >= 18
  • PostgreSQL >= 10
  • pg >= 8 (peer dependency). pg-boss ships with the engine and needs no setup.

Acknowledgments

Temporal, Inngest, Trigger.dev, and DBOS pioneered the durable execution patterns this project builds on.

On this page