0
0
Supabasecloud~5 mins

Creating Edge Functions with Deno in Supabase - Performance & Efficiency

Choose your learning style9 modes available
Time Complexity: Creating Edge Functions with Deno
O(n)
Understanding Time Complexity

When creating Edge Functions with Deno on Supabase, it's important to understand how the time to deploy and execute these functions changes as you add more functions or handle more requests.

We want to know how the number of functions or requests affects the total time spent.

Scenario Under Consideration

Analyze the time complexity of deploying multiple Edge Functions and handling requests.


// Deploy multiple edge functions
for (let i = 0; i < n; i++) {
  await supabase.functions.deploy(`function${i}`, `./functions/function${i}`)
}

// Handle requests to a single function
const response = await supabase.functions.invoke('function0', { body: requestData })

This sequence deploys n Edge Functions one by one, then invokes one function to handle a request.

Identify Repeating Operations

Look at what repeats as input size grows.

  • Primary operation: Deploying each Edge Function via supabase.functions.deploy.
  • How many times: Exactly n times, once per function.
  • Invocation operation: Calling supabase.functions.invoke once, regardless of n.
How Execution Grows With Input

As you add more functions, deployment time grows because each function is deployed separately.

Input Size (n)Approx. Deploy Calls
1010 deploy calls
100100 deploy calls
10001000 deploy calls

Deployment time grows directly with the number of functions. Invoking a single function stays the same time regardless of n.

Final Time Complexity

Time Complexity: O(n)

This means the total deployment time grows linearly as you add more Edge Functions.

Common Mistake

[X] Wrong: "Deploying multiple functions happens all at once, so time stays the same no matter how many functions I add."

[OK] Correct: Each function deploy is a separate action that takes time, so total time adds up as you deploy more functions.

Interview Connect

Understanding how deployment and invocation scale helps you design efficient cloud workflows and shows you can think about real-world costs in cloud projects.

Self-Check

What if you deployed all functions in parallel instead of one by one? How would the time complexity change?