0
0
Supabasecloud~5 mins

Invoking Edge Functions from client in Supabase - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Invoking Edge Functions from client
O(n)
Understanding Time 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?

Scenario Under Consideration

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 Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Calling supabase.functions.invoke to run the Edge Function.
  • How many times: Exactly n times, once per loop iteration.
How Execution Grows With Input

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
1010 calls
100100 calls
10001000 calls

Pattern observation: The number of calls grows in a straight line as n increases.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows proportionally with the number of Edge Function calls you make.

Common Mistake

[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.

Interview Connect

Understanding how your client-side calls scale helps you design apps that stay fast and responsive as they grow.

Self-Check

"What if instead of calling the Edge Function n times, you batch all requests into one call? How would the time complexity change?"