keepcalculator

06 Numbers and Powers

Choose the Right Trigger for Supabase Edge Workflows

Card No. 06·15447 · Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered
You enter
Finish time, Distance
You get
Average pace, Average speed
Rounding
2 dp

To choose the right trigger for a Supabase Edge Workflow, you must decide between Database, Cron, and Webhook triggers—each fires on a different event type. Database triggers react to row changes, Cron triggers run on a schedule, and Webhook triggers respond to external HTTP calls. This article explains the differences, how to pick the right one, and common pitfalls.

What Are Supabase Edge Workflows?

Supabase Edge Workflows let you run serverless functions at the edge, close to your users, without managing servers. They are built on Deno and deploy globally. Workflows are triggered by events, and the trigger type determines when and how your code runs. Supabase offers three primary trigger types:

  • Database triggers – fire on INSERT, UPDATE, DELETE, or TRUNCATE operations on a table.
  • Cron triggers – fire at scheduled times, using cron expressions.
  • Webhook triggers – fire when an HTTP request hits a specific URL.

Each trigger has its own use case, and choosing the wrong one can cause missed events, wasted compute, or security issues.

How Each Trigger Works

Database Triggers

Database triggers are the most common. They listen to changes on a table and run your workflow with the changed row data. For example, when a user signs up, you might insert a row into a profiles table; a database trigger can then send a welcome email. The trigger receives the old and new row (for UPDATE) or just the new row (for INSERT). You can filter by operation type, and you can access the row’s columns in your function.

Cron Triggers

Cron triggers run on a schedule, like every hour or every day at midnight. They don’t depend on any database event. Use them for periodic tasks: sending daily digest emails, cleaning up expired sessions, or fetching external data. You define the schedule using standard cron syntax (e.g., 0 9 * * * for 9 AM daily). The function receives no event payload—it just runs.

Webhook Triggers

Webhook triggers expose an HTTP endpoint that you can call from anywhere. This is useful for integrating with third-party services (like Stripe or GitHub) that send events via HTTP POST. You can also call it from your frontend for actions that don’t need to be tied to a database change. The function receives the HTTP request body, headers, and method.

How to Choose the Right Trigger

Ask yourself: what event should start the workflow?

  • If the workflow must run immediately after a database row is created, updated, or deleted → Database trigger.
  • If the workflow must run at a fixed time or interval, regardless of data changes → Cron trigger.
  • If the workflow is invoked by an external system or a manual user action that isn’t a database change → Webhook trigger.

For example, if you want to send a notification when a new order is placed, use a database trigger on the orders table. If you want to send a weekly summary of all orders, use a cron trigger. If you want to let a third-party service push order data into your system, use a webhook trigger.

Common Scenarios and Pitfalls

Database Trigger Pitfalls

  • Recursive triggers: If your workflow updates the same table that triggered it, you can cause an infinite loop. Use a guard condition or update a different table.
  • Missing old row data: For INSERT, there is no old row. For DELETE, there is no new row. Access only the fields that exist.
  • Large row changes: If you update many rows at once, the trigger fires once per row, which can be expensive. Consider batching or using a cron trigger to process changes periodically.

Cron Trigger Pitfalls

  • Timezone confusion: Cron schedules are in UTC. If you want 9 AM local time, convert accordingly.
  • Overlapping runs: If a run takes longer than the interval, you might have overlapping executions. Design your function to be idempotent or use a lock.

Webhook Trigger Pitfalls

  • Security: Anyone with the URL can invoke the webhook. Use a secret header or verify the sender.
  • Payload size: HTTP requests have size limits. For large payloads, consider uploading to storage and passing a reference.

Comparing Trigger Types

Trigger Event Source Latency Use Case
Database Row changes Immediate Reactive data processing
Cron Time schedule Scheduled Periodic tasks
Webhook HTTP request Immediate External integrations

Latency for database and webhook triggers is near real-time, but cron triggers have a delay up to the schedule interval. If you need a task to run exactly at a specific time, a cron trigger is the only option. If you need to react to an event within seconds, use database or webhook.

Cost and Performance Considerations

Edge Workflows are billed based on execution time and number of invocations. Database triggers can cause a high number of invocations if your table has heavy write activity. Cron triggers run at fixed intervals, so you can estimate costs easily. Webhook triggers are only invoked when called, so costs depend on external traffic. To reduce costs, avoid unnecessary triggers and filter events as early as possible. For example, a database trigger can check a condition before running the full workflow.

Performance-wise, edge functions are fast, but network calls to external APIs add latency. If your workflow needs to call a slow third-party service, consider doing it asynchronously or using a queue.

Alternatives and Advanced Patterns

Sometimes you need more than one trigger. Supabase allows you to create multiple workflows, each with its own trigger. You can also chain workflows by having one workflow call another via HTTP. For complex event processing, consider using a message queue like RabbitMQ or Kafka, but that adds infrastructure. For simpler needs, stick with the built-in triggers.

A common pattern is to use a database trigger to enqueue a job, and a cron trigger to process the queue. This decouples the event from the processing and allows batching.

Frequently Asked Questions

Can I use multiple triggers for the same workflow?

No, each workflow has exactly one trigger. If you need to start the same logic from different events, create separate workflows that call a shared function or use a webhook that is called by both the database trigger (via a separate workflow) and external systems.

How do I pass data to a database trigger?

The trigger automatically provides the old and new row data as a JSON object. You can access columns like event.data.new.column_name. For INSERT, old is null; for DELETE, new is null.

Can I schedule a cron trigger in a specific timezone?

Supabase cron triggers use UTC. You can adjust the cron expression to match your local time, but you must handle daylight saving changes manually. Some developers use a webhook trigger with an external scheduler (like cron-job.org) to handle timezones.

Is there a limit to how often a cron trigger can run?

You can set cron expressions to run as often as every minute. However, be mindful of your plan’s rate limits. Running every second is not supported.

How do I secure a webhook trigger?

Add a secret header that your function checks. For example, you can require an Authorization header with a token. Do not rely on URL obscurity alone.

What happens if my workflow fails?

Supabase retries failed executions a few times, then logs the error. You can view logs in the dashboard. For critical workflows, add error handling and alerting.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0 | 100000
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →