Why social login improves conversion in Firebase - Performance Analysis
We want to understand how adding social login affects the number of operations in Firebase authentication.
Specifically, how does the work grow when more users use social login?
Analyze the time complexity of the following Firebase social login process.
const provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider)
.then((result) => {
const user = result.user;
// Save user info to database
return firebase.firestore().collection('users').doc(user.uid).set({
name: user.displayName,
email: user.email
});
});
This code lets a user sign in with Google and then saves their info to the database.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: signInWithPopup call to authenticate user via Google.
- How many times: Once per user login attempt.
- Secondary operation: Writing user data to Firestore database.
- How many times: Once per successful login.
Each new user triggers one authentication and one database write.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 signInWithPopup + 10 database writes = 20 operations |
| 100 | 100 signInWithPopup + 100 database writes = 200 operations |
| 1000 | 1000 signInWithPopup + 1000 database writes = 2000 operations |
Pattern observation: Operations grow directly with the number of users logging in.
Time Complexity: O(n)
This means the work grows linearly as more users use social login.
[X] Wrong: "Social login reduces operations to constant time regardless of users."
[OK] Correct: Each user still triggers separate authentication and database writes, so operations increase with users.
Understanding how user actions translate to backend operations helps you design scalable systems and explain trade-offs clearly.
What if we cached user data locally after first login? How would that affect the number of database writes and overall time complexity?