Phone number authentication in Firebase - Time & Space Complexity
We want to understand how the time needed to verify phone numbers changes as more users try to sign in.
How does the system handle more requests and how does that affect speed?
Analyze the time complexity of the following operation sequence.
const phoneNumber = "+1234567890";
const appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(confirmationResult => {
// User receives SMS code
const code = prompt('Enter the verification code');
return confirmationResult.confirm(code);
})
.then(userCredential => {
// User signed in
})
.catch(error => {
// Handle errors
});
This code sends a verification SMS to the user and then confirms the code they enter to sign them in.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Sending SMS verification via Firebase API.
- How many times: Once per user sign-in attempt.
Each new user triggers one SMS send and one verification check.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 SMS sends + 10 code verifications |
| 100 | 100 SMS sends + 100 code verifications |
| 1000 | 1000 SMS sends + 1000 code verifications |
Pattern observation: The number of operations grows directly with the number of users trying to sign in.
Time Complexity: O(n)
This means the time needed grows linearly as more users try to authenticate with their phone numbers.
[X] Wrong: "Sending one SMS code will handle multiple users at once, so time stays the same."
[OK] Correct: Each user needs their own SMS and verification, so the system must do separate work for each user.
Understanding how authentication scales helps you design systems that stay fast and reliable as more people use them.
"What if we batch phone number verifications instead of sending SMS one by one? How would the time complexity change?"