0
0
Firebasecloud~5 mins

Why Firebase Hosting serves web apps - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why Firebase Hosting serves web apps
O(n)
Understanding Time Complexity

We want to understand how the time to serve a web app changes as more users request it from Firebase Hosting.

How does Firebase handle many requests and how does that affect response time?

Scenario Under Consideration

Analyze the time complexity of serving web app files from Firebase Hosting.


// User requests a web app page
firebaseHosting.serve = function(request) {
  var cacheCheck = checkCache(request.url);
  if (cacheCheck.hit) {
    return cacheCheck.content;
  } else {
    var content = fetchFromStorage(request.url);
    cacheStore(request.url, content);
    return content;
  }
}
    

This sequence shows how Firebase Hosting serves a web app by first checking cache, then fetching from storage if needed.

Identify Repeating Operations

Look at what happens each time a user requests a page.

  • Primary operation: Checking cache and possibly fetching files from storage.
  • How many times: Once per user request.
How Execution Grows With Input

As more users request the app, Firebase Hosting handles each request similarly.

Input Size (n)Approx. Api Calls/Operations
1010 cache checks, some fetches if cache misses
100100 cache checks, some fetches if cache misses
10001000 cache checks, some fetches if cache misses

Pattern observation: The number of operations grows linearly with the number of requests.

Final Time Complexity

Time Complexity: O(n)

This means the time to serve requests grows directly in proportion to the number of requests.

Common Mistake

[X] Wrong: "Firebase Hosting serves all users instantly with no extra work as users increase."

[OK] Correct: Each user request still requires checking cache or fetching files, so work grows with users.

Interview Connect

Understanding how cloud services handle many requests helps you design scalable apps and explain performance in real projects.

Self-Check

"What if Firebase Hosting had no cache and fetched files from storage every time? How would the time complexity change?"