Magic link authentication in Supabase - Time & Space 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.
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 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.
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 |
|---|---|
| 10 | 10 email sends |
| 100 | 100 email sends |
| 1000 | 1000 email sends |
Pattern observation: The number of email sends grows linearly as more users request magic links.
Time Complexity: O(n)
This means the time to send magic links grows directly in proportion to the number of login requests.
[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.
Understanding how user requests scale helps you design systems that handle growth smoothly and keep users happy.
"What if we batch magic link emails to send multiple at once? How would the time complexity change?"