Build an ETL Pipeline from a REST API Using Python, Polars, and DuckDB
Extract data from a REST API, reshape it with Python and Polars, then run analytical SQL on it with DuckDB, all in one Kestra flow.
Audit Supabase PostgREST tables for stale pending webhook events and records. Alert Slack on backlog thresholds with automated quarantine updates.
Modern backend architectures built on Supabase rely heavily on transactional outbox patterns, asynchronous webhook triggers, and event queue tables to process customer activity, payments, and background notifications. When downstream API consumers fail, rate limits trip, or unhandled exceptions stall event processors, records frequently remain trapped in a pending or processing state.
Without automated Day 2 governance, accumulated stale records create phantom inventory reservations, cause exponential polling load against PostgreSQL, and hide silent customer-facing processing stalls from operators.
This blueprint implements a declarative governance sentinel for Supabase and PostgREST. On an automated schedule, Kestra queries the target Supabase table using native PostgREST filtering, calculates the age of pending records against operational TTL thresholds, evaluates backlog volume, dispatches structured Slack notifications on SLA breaches, and safely transitions stuck records to a quarantined state to prevent poison-pill retry loops.
periodic_stale_audit_schedule triggers the sentinel workflow on a 6-hour cron schedule (disabled by default for initial environment configuration).compute_stale_cutoff_timestamp calculates the ISO-8601 boundary timestamp using io.kestra.plugin.core.debug.Return based on stale_threshold_hours.probe_stale_pending_records executes a GET request against the Supabase PostgREST endpoint using io.kestra.plugin.supabase.Select, filtering for records where status=eq.pending and created_at=lt.<cutoff> ordered by created_at.asc.classify_stale_accumulation evaluates the retrieved row count (outputs.probe_stale_pending_records.size):HEALTHY: When 0 stale pending records exist.WARNING_STALE_DETECTED: When stale records are present below critical_count_threshold.CRITICAL_ACCUMULATION: When stale records reach or exceed critical_count_threshold.route_sentinel_classification uses io.kestra.plugin.core.flow.Switch to branch on the evaluation:CRITICAL_ACCUMULATION and WARNING_STALE_DETECTED: Evaluates alert_mode and posts a structured block-kit notification to Slack via io.kestra.plugin.slack.notifications.SlackIncomingWebhook.CRITICAL_ACCUMULATION: Evaluates auto_quarantine and dry_run. When auto_quarantine: true and dry_run: false, executes io.kestra.plugin.supabase.Update to set status: "quarantined" on matching records, logging the updated count.HEALTHY: Records a nominal audit pass.log_sentinel_audit_complete runs at the conclusion of every execution to maintain an unbroken audit history in Kestra.errors handler catches network partitions, invalid API tokens, or PostgREST gateway timeouts and alerts operators.dry_run and auto_quarantine to verify candidate records before enabling automated status mutation.ALERT for active incident paging and AUDIT_ONLY for passive compliance logging.Supabase provides real-time APIs and dashboard views, but does not natively schedule multi-step audit sweeps, evaluate complex SLA threshold logic, or safely coordinate automated quarantine updates with team alerts. Kestra provides declarative, version-controlled workflows with built-in secret masking, precise scheduling, conditional branching, native Slack alerts, and complete execution audit logging.
service_role secret) authorized to select and update rows on the target table (bypassing RLS policies).id (UUID or integer), status (text), and created_at (timestamp) columns.SUPABASE_SERVICE_ROLE_KEY: Service role API key for your Supabase project (required to read and update records regardless of RLS).SLACK_WEBHOOK: Incoming webhook URL for the target Slack channel.In Kestra OSS installations, configure secrets as base64-encoded environment variables:
SECRET_SUPABASE_SERVICE_ROLE_KEY=$(echo -n "your-service-role-key" | base64) SECRET_SLACK_WEBHOOK=$(echo -n "https://hooks.slack.com/services/T00/B00/XXXX" | base64)
Start a local PostgreSQL and PostgREST container stack using Docker:
docker network create kestra-supabase-net
docker run -d
--name supabase-db
--network kestra-supabase-net
-e POSTGRES_PASSWORD=postgres
-p 5432:5432
postgres:15-alpine
docker run -d
--name supabase-rest
--network kestra-supabase-net
-p 8000:3000
-e PGRST_DB_URI="postgres://postgres:postgres@supabase-db:5432/postgres"
-e PGRST_DB_SCHEMAS="public"
-e PGRST_DB_ANON_ROLE="postgres"
postgrest/postgrest:latest
Connect the PostgREST container to your Kestra Docker network:
docker network connect YOUR_KESTRA_NETWORK supabase-rest
Verify active networks with docker network ls.
Create the sample webhook_events table and seed test records:
docker exec -i supabase-db psql -U postgres -d postgres -c " CREATE TABLE IF NOT EXISTS public.webhook_events ( id SERIAL PRIMARY KEY, event_type TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); INSERT INTO public.webhook_events (event_type, status, created_at) VALUES ('invoice.payment_failed', 'pending', NOW() - INTERVAL '36 hours'), ('customer.subscription_deleted', 'pending', NOW() - INTERVAL '30 hours'), ('order.created', 'pending', NOW() - INTERVAL '2 hours'); "
Configure the SUPABASE_SERVICE_ROLE_KEY and SLACK_WEBHOOK secrets in your Kestra environment.
Import this blueprint into your Kestra instance.
Execute the flow manually with dry_run: true to verify that the two 30+ hour records are detected as stale without being modified.
Execute with auto_quarantine: true and dry_run: false to verify that the stale records are updated to quarantined.
Enable periodic_stale_audit_schedule to begin automated 6-hour operational sweeps.
io.kestra.plugin.supabase.Delete.invitations, order_sessions, outbox_events) using io.kestra.plugin.core.flow.Loop.service_role key in SUPABASE_SERVICE_ROLE_KEY rather than the public anon key.2026-10-15T00:00:00+00:00). Using space-separated timestamp strings will result in PostgREST HTTP 400 Bad Request query errors.auto_quarantine requires dry_run: false to apply updates. If dry_run remains true, mutations are skipped regardless of auto_quarantine setting.http://localhost:8000 refers to the Kestra container itself. Use the container hostname http://supabase-rest:3000 or the host gateway on a shared bridge network.