Database / Supabase basics Interview Questions
When should you use an Edge Function instead of a Postgres database function?
Both let you run custom logic, but they suit different jobs. A Postgres function (written in SQL or PL/pgSQL and callable via RPC) is the right choice when the logic is fundamentally about data: aggregations, multi-table transactions, or anything that benefits from running inside the database's own transaction boundary.
An Edge Function is the better fit when the logic needs to reach outside the database: calling a third-party REST API, verifying a webhook signature, sending an email through an external provider, or using a secret credential that shouldn't live inside SQL. Edge Functions also make sense when you need a general-purpose runtime (npm packages, async HTTP calls) rather than SQL's more limited procedural surface.
A common pattern combines both: a database trigger calls a webhook that invokes an Edge Function, so a data change (like a new order row) triggers external side effects (like a payment charge) without the client needing to orchestrate the sequence itself.
More Related questions...