0
0
Firebasecloud~5 mins

Why file storage is needed in Firebase - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why file storage is needed
O(n)
Understanding Time Complexity

We want to understand how storing files in Firebase grows in cost as we add more files.

How does the number of files affect the work Firebase does?

Scenario Under Consideration

Analyze the time complexity of uploading multiple files to Firebase Storage.


const uploadFiles = async (files) => {
  for (const file of files) {
    const storageRef = firebase.storage().ref().child(file.name);
    await storageRef.put(file);
  }
};
    

This code uploads each file one by one to Firebase Storage.

Identify Repeating Operations

Look at what repeats as we add more files.

  • Primary operation: Uploading a single file using storageRef.put(file).
  • How many times: Once for each file in the list.
How Execution Grows With Input

Each new file means one more upload operation.

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

Pattern observation: The number of uploads grows directly with the number of files.

Final Time Complexity

Time Complexity: O(n)

This means the work grows in a straight line as you add more files.

Common Mistake

[X] Wrong: "Uploading many files takes the same time as uploading one file."

[OK] Correct: Each file needs its own upload, so more files mean more work and time.

Interview Connect

Understanding how file uploads scale helps you design apps that handle many files smoothly.

Self-Check

"What if we upload files in parallel instead of one by one? How would the time complexity change?"