How to solve long latency with Edge Functions?

I'm making an MMO right now that heavily relies on Edge functions for game logic. Currently my edge functions take ~400-600ms to run even though it's a very small function, and I also see that the edge function keeps shutting down and booting up. I can't afford to have this latency in production, and was wondering which would be the better solution for me: To upgrade to pro(if that even solves any of the latency issues) or to self host? I'm not sure if self-hosted supabase has this edge function problem of shutting down/booting up, ideally the edge function server would be online 24/7. I'm also not sure how I would go about replication in future when the time comes to launch my game.
12 Replies
inder
inder•4w ago
Edge functions are basically serverless functions. This is how they work with any cloud provider, boot up when a request is made and if the request is not made again to the function for some duration they shut down.
David.Stanton
David.Stanton•4w ago
@uldynia 🪻 What are you needing to do? do you need near "real time/ dynamic" or is it creating something that stay static for X amount of time?
uldynia 🪻
uldynia 🪻OP•4w ago
Yep, my app requires edge functions for game logic. It's called whenever the user clicks a button in the app. The data in this game is sensitive so the client can't be trusted for this logic. Attached is a video of the app prototype.
uldynia 🪻
uldynia 🪻OP•4w ago
As the user will expect a response for each button that is pressed, low latency is pretty important For context both me and the server that I chose for my Supabase are in the same country I'm thinking of multiple solutions now including • self-hosting just the JavaScript function in an API that will talk to my database directly(not sure if this will have latency) • self-hosting the whole Supabase(I'm worried about managing it and also downtime) • using database functions instead of edge functions(but I'm not sure if this is reliable and if I can verify user's identities like this)
David.Stanton
David.Stanton•4w ago
@uldynia 🪻 dont think my suggestion will help you here, its more for "static" if something only updates/ is needed every 1,5,10 mins or so
uldynia 🪻
uldynia 🪻OP•4w ago
Probably thousands of users will be calling this every second Hopefully it will stay awake throughout and have low latency
David.Stanton
David.Stanton•4w ago
@uldynia 🪻 I guess whats not known , is how many pops does the edge functions use and where are they, I cant find info on that anywhere, might be having an effect
uldynia 🪻
uldynia 🪻OP•4w ago
Pops? One FETCH to get the user's data, some json processing and one UPDATE, all based on the primary key, no joint queries or anything. Table structure is uuid user_id, jsonb gamedata
David.Stanton
David.Stanton•4w ago
if your db is in usa and the edge function pop is in germany, your gonna get "latency"?
uldynia 🪻
uldynia 🪻OP•4w ago
Yep I know my db is in my own country but im not sure if my edge function is hosted here
David.Stanton
David.Stanton•4w ago
where the EF pops are, i not got a clue, cant find out the info anywhere. It would be a suggestion for SB to have some "map" that shows them, so people can see @silentworks. Same with storage buckets
silentworks
silentworks•4w ago
I'm not a Supabase staff. It's best you make a suggestion on their GitHub discussions https://github.com/orgs/supabase/discussions/categories/feature-requests for such a feature.

Did you find this page helpful?