Workflow orchestration that runs in your Supabase project

1 min read Original article ↗

Processes web articles by fetching content, generating summaries and keywords in parallel, then publishing the results. Demonstrates parallel execution, automatic retries, and dependency management.

▸ Orchestration in Postgres

The pgflow client calls SQL function start_flow() via Supabase RPC, which creates a run and initializes state for each step. Root steps (no dependencies) get tasks queued immediately.

Edge Function worker polls the queue, calls SQL function start_tasks() to reserve tasks, executes handlers, then calls complete_task() to save outputs.

complete_task() checks dependencies after each completion, creates tasks for steps with all dependencies met, and marks the run complete when remaining_steps = 0.

Supabase Realtime streams database events. The pgflow client transforms these into a developer-friendly API with promises for completion and reactive state updates.

▸ Configuration options

slug: "article_flow"

Unique identifier for this flow. Must be ≤128 characters, containing only letters, numbers, and underscores.

maxAttempts: 2

Maximum total attempts allowed. With 2 attempts: 1 initial try + 1 retry on failure.

baseDelay: 1

Base delay for retries in seconds. With exponential backoff, first retry waits 1s (subsequent retries would wait 2s, 4s, etc).