Skip to content

# Choose your approach

pgflow workflows can be started from multiple places. Choose the approach that best fits your use case.

## Comparison

Section titled “Comparison”

Approach | Use When | Real-Time Updates | Complexity
--- | --- | --- | ---
TypeScript Client | Building apps that show live progress to users | ✅ Built-in | Medium
Supabase RPC | Simple fire-and-forget triggers from code | ⚠️ Via Client | Low
pg_cron | Running recurring tasks on a schedule | ⚠️ Via Client | Low
Database Triggers | Reacting automatically to data changes | ⚠️ Via Client | Medium

Tip

Flows started by any method can be monitored in real-time using the TypeScript Client’s `getRun()` method. Only the TypeScript Client provides built-in real-time monitoring when starting flows.

## TypeScript Client

Section titled “TypeScript Client”

Use `@pgflow/client` when building applications that need to stream real-time progress updates to users.

Best for:

- AI generation progress bars
- Multi-step workflow visualization
- Interactive dashboards
- Real-time status updates in browsers

    import { PgflowClient } from '@pgflow/client';
    const pgflow = new PgflowClient(supabase);const run = await pgflow.startFlow('process_video', { url });run.on('*', (event) => console.log(event.status));await run.waitForStatus('completed');

## Supabase RPC

Section titled “Supabase RPC”

Use RPC calls when you just need to trigger workflows without real-time updates.

Best for:

- Fire-and-forget workflows
- Simple background jobs

    await supabase.schema('pgflow').rpc('start_flow', {  flow_slug: 'send_email',  input: { to: 'user@example.com' }});

## Scheduled Tasks

Section titled “Scheduled Tasks”

Use pg_cron to run workflows on a recurring schedule.

Best for:

- Periodic data syncing
- Scheduled reports
- Cleanup tasks
- Time-based automation

    SELECT cron.schedule(  'daily-sync',  '0 2 * * *',  $$ SELECT pgflow.start_flow('sync_data', '{}') $$);

## Event-Driven

Section titled “Event-Driven”

Use database triggers to automatically start workflows when data changes.

Best for:

- Processing new records automatically
- Reacting to data changes

    -- Trigger function starts a workflow for each new orderCREATE FUNCTION process_new_orders()RETURNS TRIGGER AS $$BEGIN  PERFORM pgflow.start_flow(    flow_slug => 'process_order',    input => jsonb_build_object(      'order_id', new_orders.id,      'customer_id', new_orders.customer_id    )  )  FROM new_orders;  RETURN NULL;END;$$ LANGUAGE plpgsql;
    -- Trigger fires once per INSERT statementCREATE TRIGGER on_order_created  AFTER INSERT ON orders  REFERENCING NEW TABLE AS new_orders  FOR EACH STATEMENT  EXECUTE FUNCTION process_new_orders();

## Detailed Guides

Section titled “Detailed Guides”
TypeScript Client Full client library with real-time streaming and event subscriptions
Supabase RPC Simple RPC calls for fire-and-forget workflow triggering
pg_cron Run workflows on a recurring schedule with cron expressions
Database Triggers Automatically start workflows when database records change