Invoking Edge Functions from client in Supabase - Time & Space Complexity
When calling Edge Functions from a client app, it's important to understand how the number of calls grows as your app needs more data or actions.
We want to know: how does the work increase when the client makes more requests?
Analyze the time complexity of the following operation sequence.
// Client calls multiple Edge Functions
for (let i = 0; i < n; i++) {
const response = await supabase.functions.invoke('my-edge-function', {
body: JSON.stringify({ index: i })
})
// process response
}
This code calls an Edge Function n times, each time sending a request and waiting for a response.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling
supabase.functions.invoketo run the Edge Function. - How many times: Exactly n times, once per loop iteration.
Each new request adds one more call to the Edge Function, so the total calls grow directly with n.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of calls grows in a straight line as n increases.
Time Complexity: O(n)
This means the total time grows proportionally with the number of Edge Function calls you make.
[X] Wrong: "Calling multiple Edge Functions at once will take the same time as calling one."
[OK] Correct: Each call takes time and resources, so more calls add more total time.
Understanding how your client-side calls scale helps you design apps that stay fast and responsive as they grow.
"What if instead of calling the Edge Function n times, you batch all requests into one call? How would the time complexity change?"