Multiple site hosting in Firebase - Time & Space Complexity
When hosting multiple sites on Firebase, it's important to understand how the work grows as you add more sites.
We want to know how the number of steps or calls changes when managing many sites together.
Analyze the time complexity of deploying multiple sites using Firebase Hosting.
firebase deploy --only hosting:site1,hosting:site2,hosting:site3
// This command deploys three different sites in one go.
// Each site has its own configuration and files.
This sequence deploys multiple hosting sites in a single Firebase project.
Look at what repeats when deploying multiple sites.
- Primary operation: Uploading files for each site to Firebase servers.
- How many times: Once per site, for all files in that site.
As you add more sites, the total upload and deployment steps increase roughly by the number of sites.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 1 site | 1 set of uploads and deploy calls |
| 5 sites | 5 sets of uploads and deploy calls |
| 20 sites | 20 sets of uploads and deploy calls |
Pattern observation: The work grows directly with the number of sites you deploy.
Time Complexity: O(n)
This means the deployment time grows in a straight line as you add more sites.
[X] Wrong: "Deploying multiple sites at once takes the same time as deploying one site."
[OK] Correct: Each site has its own files and settings, so Firebase must handle each separately, making the total time add up.
Understanding how deployment time grows with the number of sites shows you can plan and manage cloud resources well, a useful skill in real projects.
"What if we used a single shared site configuration for all sites instead of separate ones? How would the time complexity change?"
Practice
Solution
Step 1: Understand multiple site hosting purpose
Multiple site hosting allows managing multiple websites within a single Firebase project.Step 2: Compare options
Options B, C, and D relate to other Firebase features, not multiple site hosting.Final Answer:
Manage several websites under one Firebase project -> Option AQuick Check:
Multiple site hosting = Manage multiple sites [OK]
- Confusing hosting with database features
- Thinking it creates new Firebase projects
- Assuming it automatically increases storage
Solution
Step 1: Identify configuration file for hosting
Thefirebase.jsonfile holds hosting configurations including multiple sites.Step 2: Eliminate other files
index.htmlis a webpage,package.jsonis for Node.js dependencies, and.firebasercstores project aliases but not hosting sites.Final Answer:
firebase.json -> Option DQuick Check:
Hosting sites defined in firebase.json [OK]
- Editing .firebaserc instead of firebase.json
- Confusing package.json with Firebase config
- Trying to define sites in index.html
firebase.json:
{
"hosting": [
{
"target": "siteA",
"public": "publicA"
},
{
"target": "siteB",
"public": "publicB"
}
]
}
What command links the target siteA to a Firebase Hosting site ID?Solution
Step 1: Understand target linking command
The commandfirebase target:apply hosting <target> <site-id>links a target name to a Firebase Hosting site ID.Step 2: Review options
firebase deploy --only hosting:siteA deploys hosting but does not link targets. firebase init hosting siteA initializes hosting but does not link targets. firebase hosting:link siteA your-site-id is not a valid Firebase CLI command.Final Answer:
firebase target:apply hosting siteA your-site-id -> Option AQuick Check:
Target apply links target to site ID [OK]
- Using deploy instead of target:apply to link
- Trying to link with firebase init
- Assuming 'hosting:link' is a valid command
firebase.json hosting array but forgot to run firebase target:apply hosting. What happens when you deploy?Solution
Step 1: Understand target linking requirement
Each hosting target must be linked to a Firebase Hosting site ID usingfirebase target:apply hosting.Step 2: Consequence of missing link
If targets are not linked, deployment fails with an error indicating missing target link.Final Answer:
Deployment fails with an error about missing target link -> Option CQuick Check:
Missing target link causes deployment error [OK]
- Assuming Firebase auto-links targets
- Expecting silent ignore of unlinked sites
- Thinking deployment creates new site IDs
firebase.json hosting array with targets blog and store. Which sequence correctly sets up and deploys both sites?Solution
Step 1: Link each target to its Firebase Hosting site ID
Usefirebase target:apply hosting <target> <site-id>for both blog and store targets.Step 2: Deploy all hosting targets
Runfirebase deploy --only hostingto deploy all defined hosting sites.Final Answer:
Run target:apply for blog and store, then deploy hosting -> Option BQuick Check:
Link targets first, then deploy hosting [OK]
- Deploying without linking targets
- Trying to define sites only in .firebaserc
- Using firebase init hosting multiple times incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
