0
0
Firebasecloud~5 mins

Why push notifications engage users in Firebase - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why push notifications engage users
O(n)
Understanding Time Complexity

We want to understand how the work needed to send push notifications changes as more users get them.

How does the number of users affect the effort to send notifications?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


const messaging = getMessaging();
const tokens = await getUserTokens();
for (const token of tokens) {
  await sendPushNotification(messaging, token, messagePayload);
}
    

This code gets all user tokens and sends a push notification to each user one by one.

Identify Repeating Operations

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

  • Primary operation: Sending a push notification to one user token.
  • How many times: Once for each user token in the list.
How Execution Grows With Input

As the number of users grows, the number of notifications sent grows the same way.

Input Size (n)Approx. API Calls/Operations
1010 notifications sent
100100 notifications sent
10001000 notifications sent

Pattern observation: The work grows directly with the number of users.

Final Time Complexity

Time Complexity: O(n)

This means sending notifications takes longer as more users get them, growing in a straight line.

Common Mistake

[X] Wrong: "Sending one notification automatically sends it to all users at once."

[OK] Correct: Each user needs their own notification sent, so the work adds up with more users.

Interview Connect

Understanding how work grows with users helps you design systems that handle many users smoothly.

Self-Check

"What if we send notifications in batches instead of one by one? How would the time complexity change?"