Workflow Automation for Self-Hosted Supabase with n8n

Connect self-hosted Supabase to n8n for powerful database automation. Build triggers, sync data, and create AI workflows.

Cover Image for Workflow Automation for Self-Hosted Supabase with n8n

When you self-host Supabase, you gain full control over your database and infrastructure. But what about connecting it to the rest of your stack? Workflow automation platforms like n8n let you build powerful integrations—syncing data, triggering actions on database changes, and even orchestrating AI workflows—all without writing custom backend code.

The best part? n8n can also be self-hosted, giving you a fully sovereign automation stack that keeps your data on your own servers.

Why Automate Self-Hosted Supabase?

Self-hosting Supabase gives you control and significant cost savings, but it also means you're responsible for building integrations that cloud platforms might handle automatically. Workflow automation bridges this gap.

Common automation use cases include:

  • New user onboarding: When a row is inserted into your users table, send a welcome email via SendGrid, create a Slack notification, and add the user to your CRM
  • Data synchronization: Keep your Supabase database in sync with external systems like Airtable, Google Sheets, or your accounting software
  • Webhook processing: Handle Stripe payment events, GitHub webhooks, or any external service that needs to update your database
  • Scheduled reports: Generate daily summaries, weekly analytics, or monthly billing reports from your database
  • AI-powered workflows: Use database changes to trigger AI processing—summarizing content, generating embeddings, or running classification tasks

n8n: The Self-Hosted Automation Platform

n8n has emerged as the go-to automation platform for developers who want Zapier-like functionality without the Zapier pricing. It's open source, self-hostable, and designed for technical users who need flexibility.

Key advantages for self-hosted Supabase users:

  1. Self-host everything: Run n8n on the same server or cluster as your Supabase instance, keeping all data internal
  2. No per-execution fees: Unlike Zapier's $300+/month for moderate usage, self-hosted n8n is free for unlimited executions
  3. Native Supabase integration: Pre-built nodes for common database operations without writing code
  4. AI capabilities: Built-in LangChain nodes, vector database support (including pgvector), and Ollama integration for local LLMs

Setting Up n8n with Self-Hosted Supabase

Prerequisites

Before connecting n8n to your Supabase instance, you'll need:

Option 1: Add n8n to Your Existing Stack

The simplest approach is adding n8n to your existing Docker Compose configuration. Create a new service:

# docker-compose.override.yml
services:
  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=n8n.yourdomain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.yourdomain.com/
      - GENERIC_TIMEZONE=UTC
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=${POSTGRES_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - db

volumes:
  n8n_data:

Option 2: Standalone n8n Instance

For production workloads, consider running n8n on a separate server. This isolates your automation workloads and prevents resource contention with your database.

# Quick start with Docker
docker run -d \
  --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  n8nio/n8n:latest

Configuring the Supabase Connection

In the n8n interface, create a new credential for Supabase:

  1. Navigate to Settings → Credentials → Add Credential
  2. Select Supabase from the list
  3. Enter your self-hosted Supabase details:
    • Host: Your Supabase API URL (e.g., https://supabase.yourdomain.com)
    • Service Role Key: Found in your environment variables

For self-hosted instances, you'll use your custom domain rather than *.supabase.co. If you haven't configured custom domains yet, check out our custom domains setup guide.

Building Your First Workflow

Let's create a practical workflow: automatically sending a welcome email when a new user signs up.

Workflow Overview

Supabase Trigger (Insert on auth.users)
    ↓
Send Email (via SendGrid/SMTP)
    ↓
Update User Record (mark welcome_sent = true)

Step 1: Create the Trigger

Since n8n's native Supabase node uses polling (checking for changes every few minutes), we'll use a more responsive approach with database webhooks.

In your Supabase database, create a webhook trigger:

-- Enable pg_net extension if not already enabled
create extension if not exists pg_net;

-- Create a function to send webhook on new user
create or replace function notify_n8n_new_user()
returns trigger as $$
begin
  perform net.http_post(
    url := 'https://n8n.yourdomain.com/webhook/new-user',
    body := jsonb_build_object(
      'id', new.id,
      'email', new.email,
      'created_at', new.created_at
    ),
    headers := '{"Content-Type": "application/json"}'::jsonb
  );
  return new;
end;
$$ language plpgsql security definer;

-- Attach trigger to auth.users table
create trigger on_user_created
  after insert on auth.users
  for each row execute function notify_n8n_new_user();

Step 2: Configure n8n Webhook Node

In n8n:

  1. Add a Webhook node
  2. Set the path to /new-user
  3. Set HTTP method to POST
  4. Configure authentication if needed (basic auth or header-based)

Step 3: Send the Welcome Email

Add an email node (SendGrid, SMTP, or your preferred provider):

{
  "to": "{{ $json.email }}",
  "subject": "Welcome to our platform!",
  "body": "Thanks for signing up. We're excited to have you!"
}

Step 4: Update the User Record

Add a Supabase node to mark the welcome email as sent:

  • Operation: Update
  • Table: profiles (or your custom table)
  • Match Column: id
  • Match Value: {{ $json.id }}
  • Fields: { "welcome_sent": true }

Advanced Patterns

Pattern 1: Scheduled Data Aggregation

Use n8n's Schedule Trigger to run periodic database queries:

// n8n Code Node - Generate daily stats
const stats = await this.helpers.httpRequest({
  method: 'POST',
  url: `${credentials.supabaseUrl}/rest/v1/rpc/get_daily_stats`,
  headers: {
    'apikey': credentials.supabaseKey,
    'Authorization': `Bearer ${credentials.supabaseKey}`,
    'Content-Type': 'application/json'
  },
  body: { date: new Date().toISOString().split('T')[0] }
});

return { json: stats };

Pattern 2: AI-Powered Content Processing

Combine n8n's AI nodes with Supabase for intelligent data processing:

  1. Trigger: New content inserted into your posts table
  2. AI Node: Generate embeddings using OpenAI or a local model via Ollama
  3. Supabase Node: Store embeddings in your pgvector-enabled table

This pattern enables semantic search, content recommendations, and RAG applications—all running on your own infrastructure.

Pattern 3: Multi-System Sync

Keep your Supabase data synchronized with external systems:

Supabase Change → n8n → Multiple Destinations
                    ├── Google Sheets (reporting)
                    ├── Slack (notifications)
                    ├── CRM (customer data)
                    └── Analytics (event tracking)

Security Considerations

When connecting automation platforms to your database, security is paramount:

Use Service Role Keys Carefully

The service role key bypasses Row Level Security. For n8n workflows that only need to read or write specific tables, consider creating a dedicated Postgres role with limited permissions.

Secure Your Webhook Endpoints

If using webhook-based triggers:

  1. Use HTTPS exclusively
  2. Implement webhook signature verification
  3. Add IP allowlisting if n8n is on a known IP
  4. Use n8n's built-in authentication options

Network Isolation

If running n8n on the same server as Supabase, use Docker networks to limit exposure:

networks:
  internal:
    internal: true
  external:
    internal: false

Monitoring and Troubleshooting

Check n8n Execution Logs

n8n maintains execution history for all workflows. Use this to debug failed automations:

  • Executions view: See all workflow runs with success/failure status
  • Error details: Click any execution to see exactly where it failed
  • Manual execution: Test workflows with sample data before enabling triggers

Monitor Webhook Delivery

For webhook-based triggers using pg_net, check the delivery status:

select * from net._http_response
where created > now() - interval '1 hour'
order by created desc;

Database Connection Issues

If n8n can't connect to Supabase:

  1. Verify network connectivity between containers
  2. Check that your API URL is accessible from n8n's network
  3. Confirm the service role key hasn't been rotated

Cost Analysis: Self-Hosted vs Cloud Automation

The economics of self-hosted automation are compelling:

Platform10K executions/mo100K executions/mo
Zapier~$73/month~$500+/month
Make~$16/month~$83/month
n8n Cloud~$20/month~$50/month
n8n Self-HostedVPS cost onlyVPS cost only

If you're already running a VPS for Supabase, adding n8n typically requires an additional 1-2GB RAM—effectively free on most server configurations.

When to Use Alternatives

n8n isn't the only option. Consider these alternatives for specific use cases:

  • Temporal or Inngest: For complex, long-running workflows with retry logic
  • pg_cron + Edge Functions: For database-centric tasks that don't need external integrations
  • Direct API calls: For simple, single-destination webhooks where a full automation platform is overkill

Managing It All with Supascale

Configuring automation workflows is just one part of running self-hosted Supabase. Supascale simplifies the broader operational challenge—managing backups, domains, OAuth providers, and multiple projects from a single dashboard. While you focus on building automation workflows, Supascale handles the infrastructure basics.

Check out our pricing page to see how a one-time purchase can eliminate the operational overhead of self-hosted Supabase management.

Conclusion

Workflow automation transforms self-hosted Supabase from an isolated database into a connected hub that integrates with your entire stack. By combining Supabase's real-time capabilities with n8n's flexible automation, you can build sophisticated data pipelines without the complexity of custom backend code—or the costs of cloud automation platforms.

Start simple: pick one repetitive task you currently do manually, automate it, and expand from there. The combination of self-hosted Supabase and self-hosted n8n gives you enterprise-grade capabilities at indie-hacker prices.

Further Reading