Updating DB: Edge functions or RPC?
Hi, I wanted to understand what's the best practice for choosing which method to update my database?
1. Update database via edge function using supabase client directly
2. Have the edge function invoke an RPC, passing in the payload to be updated
How do you guys decide which approach to take in different scenarios? For my use case, it's a simple use case of taking in form data, performing some logic checks in the edge function before updating it in my DB.
Thanks!
1 Reply
The Supabase database client is a PostgREST deployment that lives on the same server as the DB.
If you send a request through the Supabase database client, PostgREST will translate it into SQL and then run it in Postgres. As long as you have RLS policies in place, you can call this client from anywhere. Though, you should only use the service_role from a protected server.
Edge Functions are just emphemeral deno servers. You can use the Supabase DB client from within them. Because the server is protected, you could even use the service_role if you want. Likewise, you can directly connect to Postgres with an external ORM/driver, such as Drizzle or Postgres.JS.
It doesn’t really matter which method you choose: both produce the same results. Technically, calling the Supabase Database API directly from the user’s device is slightly faster since it skips the extra network request to an Edge Function. In practice, though, the difference isn't substantial and I'd personally just go with what's more maintainable.
PostgREST 14
PostgREST Documentation
, PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations. Sponsors:,, Database as Single Source of Truth: Using PostgREST is an alternative to manua...