Custom domain configuration in Firebase - Time & Space Complexity
When setting up a custom domain in Firebase Hosting, it's important to understand how the time to complete the setup grows as you add more domains.
We want to know how the number of steps or API calls changes when configuring multiple domains.
Analyze the time complexity of adding multiple custom domains to Firebase Hosting.
const admin = require('firebase-admin');
const hosting = admin.hosting();
async function addCustomDomains(domains) {
for (const domain of domains) {
await hosting.sites().addDomain({siteId: 'my-site', domainName: domain});
}
}
This code adds each custom domain one by one to a Firebase Hosting site.
Look at what repeats as the input grows.
- Primary operation: API call to add a domain to the hosting site.
- How many times: Once per domain in the input list.
Each domain requires one API call, so the total calls grow directly with the number of domains.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 API calls |
| 100 | 100 API calls |
| 1000 | 1000 API calls |
Pattern observation: The number of API calls increases one-to-one with the number of domains.
Time Complexity: O(n)
This means the time to configure domains grows directly in proportion to how many domains you add.
[X] Wrong: "Adding multiple domains happens all at once, so time stays the same no matter how many domains."
[OK] Correct: Each domain requires a separate API call and processing step, so time grows with the number of domains.
Understanding how operations scale with input size helps you design efficient cloud setups and explain your reasoning clearly in interviews.
"What if the API allowed adding multiple domains in a single call? How would the time complexity change?"