Why analytics drive product decisions in Firebase - Performance Analysis
We want to understand how the time to gather and process analytics data changes as more users interact with a product.
How does the number of users affect the work Firebase does to collect and analyze data?
Analyze the time complexity of the following operation sequence.
const analytics = getAnalytics(app);
function logUserEvent(userId, event) {
logEvent(analytics, event, { userId: userId });
}
// Called each time a user triggers an event
This code logs an event for each user action to Firebase Analytics.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: logEvent call to send user event data to Firebase Analytics.
- How many times: Once per user event triggered in the app.
Each new user event causes one logEvent call, so the total work grows as more events happen.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 logEvent calls |
| 100 | 100 logEvent calls |
| 1000 | 1000 logEvent calls |
Pattern observation: The number of API calls grows directly with the number of user events.
Time Complexity: O(n)
This means the time to log analytics grows in direct proportion to the number of user events.
[X] Wrong: "Logging analytics events happens all at once, so time doesn't grow with more users."
[OK] Correct: Each event triggers a separate call, so more users and events mean more calls and more time.
Understanding how analytics scale helps you design systems that handle growing user activity smoothly.
"What if we batch multiple user events into one logEvent call? How would the time complexity change?"