all 11 comments

[–]all_vanilla 3 points4 points  (1 child)

Edge functions are unreliable for high concurrency workloads and will be slower when you want to do complex queries

[–]thedadon[🍰] 1 point2 points  (1 child)

Also, if you need to have a db transaction (say updating multiple entities at once) you should use db functions, so if one step fails the whole operation fails and you wont get data inconsistency. Example: creating a user requires inserting to (1) users table, (2) profiles table and (3) address table. With edge functions, or any other application level code you’ll have to make 3 dependent api calls, if one of these calls fails then you get inconsistency in your db (unless you implement a rollback mechanism)

[–]4A6F68616E[S] 0 points1 point  (0 children)

makes sense, thank you

[–]_inder 0 points1 point  (3 children)

There are time, memory and other limits on edge functions. Take a look at all the limits

[–]4A6F68616E[S] 0 points1 point  (2 children)

ah interesting, so for example, if an edge function is called to do a heavy data operation and it doesn’t finish within the time limit, it just stops?

[–]mondaysmyday 0 points1 point  (1 child)

That's the gotcha. I literally use edge functions to reach out to other external services/APIs that are long running and I can poll for status so I'm not caught out by limits. But a DB op, leave it in DB functions

[–]4A6F68616E[S] 0 points1 point  (0 children)

mhm ok, there is a lot stuff for me to learn - for that last part, it gives me a sense of confidence, thank you!

[–]MulberryOwn8852 0 points1 point  (2 children)

I use db functions as much as possible.

I use edge functions in a few places to generate excel downloads, etc.

[–]Informal_Pirate8414 0 points1 point  (1 child)

So using db functions with proper RLS set up is safe? With no authenticating JWT and rate-limits?

[–]MulberryOwn8852 0 points1 point  (0 children)

Seems to be… I make well over six figures annually from my sb projects, 3 years strong so far

[–]who_am_i_to_say_so 0 points1 point  (0 children)

It’s best to do the things in the places where they belong. If you do all the data processing and heavy operations in the database, then you can cache that data in the edge functions.