Hosting setup and deployment in Firebase - Time & Space Complexity
When setting up and deploying hosting on Firebase, it's important to know how the time to complete these steps changes as your project grows.
We want to understand how the deployment process scales with the size of your website or app files.
Analyze the time complexity of deploying a website using Firebase Hosting CLI.
firebase login
firebase init hosting
firebase deploy --only hosting
This sequence logs in, initializes hosting setup, and deploys the website files to Firebase Hosting.
Look at what happens multiple times during deployment.
- Primary operation: Uploading each file from your project to Firebase servers.
- How many times: Once per file in your website or app folder.
As you add more files, the deployment takes longer because each file is sent separately.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 files | About 10 upload operations |
| 100 files | About 100 upload operations |
| 1000 files | About 1000 upload operations |
Pattern observation: The number of upload operations grows directly with the number of files.
Time Complexity: O(n)
This means the deployment time grows in a straight line with the number of files you have to upload.
[X] Wrong: "Deploying takes the same time no matter how many files I have."
[OK] Correct: Each file must be uploaded separately, so more files mean more upload steps and longer deployment.
Understanding how deployment time grows helps you plan and explain your cloud workflows clearly, a useful skill in real projects and discussions.
What if Firebase used batch uploading to send multiple files at once? How would the time complexity change?
Practice
Solution
Step 1: Understand Firebase Hosting's role
Firebase Hosting is designed to host and serve web content easily without needing to manage servers.Step 2: Differentiate from other Firebase services
Other services like databases or backend code are separate from Hosting's purpose.Final Answer:
To publish websites online without managing servers -> Option CQuick Check:
Firebase Hosting = publish websites without servers [OK]
- Confusing Hosting with Firebase database services
- Thinking Hosting manages backend code
- Assuming Hosting monitors app performance
Solution
Step 1: Identify the initialization command
The command to set up Firebase Hosting configuration isfirebase init hosting.Step 2: Differentiate from deployment commands
firebase deploy --only hostingpublishes the site but does not initialize it.Final Answer:
firebase init hosting -> Option AQuick Check:
Initialize Hosting = firebase init hosting [OK]
- Using deploy command to initialize
- Assuming 'firebase start hosting' exists
- Confusing create with init
firebase deploy --only hosting, what happens?Solution
Step 1: Understand the deploy command effect
The deploy command uploads your site files to Firebase Hosting and makes the site live.Step 2: Eliminate incorrect options
Deploy does not delete local files, reset databases, or remove configuration.Final Answer:
Your website files are uploaded and become live at a Firebase URL -> Option BQuick Check:
Deploy Hosting = upload and go live [OK]
- Thinking deploy deletes local files
- Confusing deploy with database reset
- Assuming deploy removes Hosting setup
firebase deploy --only hosting but your site did not update. What is a likely cause?Solution
Step 1: Check project targeting
If you deploy to the wrong Firebase project, your site won't update as expected.Step 2: Rule out other options
Init is needed only once; internet speed does not block updates; Hosting supports updates.Final Answer:
You deployed to the wrong Firebase project -> Option AQuick Check:
Wrong project deploy = no site update [OK]
- Assuming init must run every deploy
- Blaming internet speed for deployment failure
- Thinking Hosting can't update sites
Solution
Step 1: Understand deployment scope flags
The--only hostingflag deploys just the Hosting service, leaving others untouched.Step 2: Compare other options
firebase deploydeploys all configured services;--only databasedeploys only database;--except hostingdeploys all except Hosting.Final Answer:
firebase deploy --only hosting -> Option DQuick Check:
Deploy only Hosting = firebase deploy --only hosting [OK]
- Running deploy without --only and affecting all services
- Using --only database instead of hosting
- Using --except hosting to deploy Hosting
Ready to prove it?
Pass the test and this pattern moves unknown
