0
0
Supabasecloud~5 mins

Supabase architecture (Postgres, Auth, Storage, Realtime, Edge Functions) - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Supabase architecture (Postgres, Auth, Storage, Realtime, Edge Functions)
O(n)
Understanding Time Complexity

We want to understand how the work done by Supabase services grows as more users or data are involved.

How does the number of operations change when we use Postgres, Auth, Storage, Realtime, and Edge Functions together?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// User signs up
const { data, error } = await supabase.auth.signUp({ email, password })

// User uploads a file
const { data: fileData, error: fileError } = await supabase.storage
  .from('avatars')
  .upload('public/avatar1.png', file)

// User fetches messages in realtime
const subscription = supabase
  .from('messages')
  .on('INSERT', payload => console.log('New message:', payload))
  .subscribe()

// User calls an edge function
const response = await supabase.functions.invoke('hello-world')

This sequence shows a user signing up, uploading a file, listening for new messages, and calling a serverless function.

Identify Repeating Operations

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

  • Primary operation: API calls to Supabase services (Auth, Storage, Realtime, Edge Functions)
  • How many times: Each user action triggers one or more calls; Realtime subscription listens continuously for new events
How Execution Grows With Input

As more users sign up and upload files, the number of API calls grows roughly with the number of users.

Input Size (n users)Approx. Api Calls/Operations
10~10 sign-ups + 10 uploads + 10 edge calls + ongoing realtime events
100~100 sign-ups + 100 uploads + 100 edge calls + ongoing realtime events
1000~1000 sign-ups + 1000 uploads + 1000 edge calls + ongoing realtime events

Pattern observation: The number of operations grows linearly with the number of users and their actions.

Final Time Complexity

Time Complexity: O(n)

This means the total work grows directly in proportion to the number of users and their actions.

Common Mistake

[X] Wrong: "Realtime subscriptions cause the system to do the same work regardless of user count."

[OK] Correct: Each active subscription listens and processes events, so more users mean more ongoing work.

Interview Connect

Understanding how service calls grow with users helps you design scalable apps and explain your architecture choices clearly.

Self-Check

"What if we batch user uploads instead of uploading one file at a time? How would the time complexity change?"