Schedule icon
Return icon
Select icon
Switch icon
If icon
SlackIncomingWebhook icon
Log icon
Update icon

Supabase Stale Pending Record and Webhook Event Quarantine Sentinel

Audit Supabase PostgREST tables for stale pending webhook events and records. Alert Slack on backlog thresholds with automated quarantine updates.

Categories
DataInfrastructure

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.

How it works

  1. periodic_stale_audit_schedule triggers the sentinel workflow on a 6-hour cron schedule (disabled by default for initial environment configuration).
  2. compute_stale_cutoff_timestamp calculates the ISO-8601 boundary timestamp using io.kestra.plugin.core.debug.Return based on stale_threshold_hours.
  3. 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.
  4. 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.
  5. route_sentinel_classification uses io.kestra.plugin.core.flow.Switch to branch on the evaluation:
    • On 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.
    • On 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.
    • On HEALTHY: Records a nominal audit pass.
  6. log_sentinel_audit_complete runs at the conclusion of every execution to maintain an unbroken audit history in Kestra.
  7. A flow-level errors handler catches network partitions, invalid API tokens, or PostgREST gateway timeouts and alerts operators.

What you get

  • Automated, continuous monitoring of Supabase tables for stuck or unconsumed records without running custom daemon scripts.
  • PostgREST-native filtering that audits database state over standard HTTP REST interfaces without requiring direct database port exposure.
  • Two-stage safety gating via dry_run and auto_quarantine to verify candidate records before enabling automated status mutation.
  • Dual alert operating modes: ALERT for active incident paging and AUDIT_ONLY for passive compliance logging.
  • Structured Slack notifications detailing table name, backlog count, and cutoff timestamps.

Who it's for

  • Platform Engineers and Full-Stack Developers managing Supabase or self-hosted PostgREST backends.
  • SREs responsible for asynchronous webhook delivery reliability and event outbox hygiene.
  • Data Operations teams tracking transactional integrity across Supabase database tables.

Why orchestrate this with Kestra

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.

Prerequisites

  • A running Supabase project (Supabase Cloud or self-hosted PostgREST instance) reachable from the Kestra worker environment.
  • A Supabase Service Role Key (service_role secret) authorized to select and update rows on the target table (bypassing RLS policies).
  • A target table containing at least id (UUID or integer), status (text), and created_at (timestamp) columns.
  • A Slack incoming webhook URL for dispatching alerts.

Secrets

  • 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)

Quick start

  1. 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

  2. Connect the PostgREST container to your Kestra Docker network:

    docker network connect YOUR_KESTRA_NETWORK supabase-rest

    Verify active networks with docker network ls.

  3. 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'); "

  4. Configure the SUPABASE_SERVICE_ROLE_KEY and SLACK_WEBHOOK secrets in your Kestra environment.

  5. Import this blueprint into your Kestra instance.

  6. Execute the flow manually with dry_run: true to verify that the two 30+ hour records are detected as stale without being modified.

  7. Execute with auto_quarantine: true and dry_run: false to verify that the stale records are updated to quarantined.

  8. Enable periodic_stale_audit_schedule to begin automated 6-hour operational sweeps.

How to extend

  • Add dead-letter archival by writing quarantined records to external object storage (AWS S3, Google Cloud Storage) before deleting them from the primary table using io.kestra.plugin.supabase.Delete.
  • Loop over multiple critical tables (e.g., invitations, order_sessions, outbox_events) using io.kestra.plugin.core.flow.Loop.
  • Integrate with PagerDuty or Opsgenie to escalate critical accumulation breaches based on business hours.
  • Implement automatic retry dispatch by publishing quarantined records back to an event broker like Apache Kafka or RabbitMQ.

Links

Pitfalls

  • Service Role Key requirement: PostgREST applies PostgreSQL Row Level Security (RLS) policies by default. When querying administrative audit tables across all users, always provide the service_role key in SUPABASE_SERVICE_ROLE_KEY rather than the public anon key.
  • Timestamp timezone formatting: PostgREST requires ISO-8601 formatted timestamps (e.g. 2026-10-15T00:00:00+00:00). Using space-separated timestamp strings will result in PostgREST HTTP 400 Bad Request query errors.
  • Two-stage safety gates: auto_quarantine requires dry_run: false to apply updates. If dry_run remains true, mutations are skipped regardless of auto_quarantine setting.
  • Container network routing: When running Kestra and Supabase/PostgREST in separate Docker containers, 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.
See How

New to Kestra?

Use blueprints to kickstart your first workflows.