0
0
Supabasecloud~5 mins

Magic link authentication in Supabase - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Magic link authentication
O(n)
Understanding Time Complexity

When using magic link authentication, it's important to know how the number of users affects the process time.

We want to understand how the system handles sending magic links as more users try to log in.

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.

const { data, error } = await supabase.auth.signInWithOtp({
  email: userEmail,
  options: { emailRedirectTo: 'https://example.com/welcome' }
});

This code sends a magic link email to a user to authenticate them without a password.

Identify Repeating Operations

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

  • Primary operation: Sending a magic link email via the authentication API.
  • How many times: Once per user login attempt.
How Execution Grows With Input

Each login attempt triggers one email send operation, so the total work grows directly with the number of users.

Input Size (n)Approx. API Calls/Operations
1010 email sends
100100 email sends
10001000 email sends

Pattern observation: The number of email sends grows linearly as more users request magic links.

Final Time Complexity

Time Complexity: O(n)

This means the time to send magic links grows directly in proportion to the number of login requests.

Common Mistake

[X] Wrong: "Sending one magic link email handles all users at once, so time stays the same no matter how many users."

[OK] Correct: Each user needs their own email, so the system must send one email per user, making time grow with user count.

Interview Connect

Understanding how user requests scale helps you design systems that handle growth smoothly and keep users happy.

Self-Check

"What if we batch magic link emails to send multiple at once? How would the time complexity change?"