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?"
Practice
Solution
Step 1: Understand Firebase Hosting default URLs
Firebase Hosting provides a default URL, but it is not personalized.Step 2: Purpose of custom domain
Configuring a custom domain lets you use your own website address, making it easier for users to find your site.Final Answer:
To use your own website address instead of the default Firebase URL -> Option DQuick Check:
Custom domain = personal website address [OK]
- Confusing custom domain with Firebase project storage
- Thinking it enables authentication automatically
- Assuming it creates a new Firebase project
Solution
Step 1: Identify verification method
Firebase asks you to add a DNS record to prove you own the domain.Step 2: Common DNS record for verification
TXT records are used to store text data for verification purposes.Final Answer:
TXT record -> Option CQuick Check:
Domain verification uses TXT record [OK]
- Using MX record which is for email routing
- Confusing CNAME with verification record
- Using A record which points IP address
www.example.com to ghs.googlehosted.com as Firebase instructed. What will happen when users visit www.example.com after DNS propagation?Solution
Step 1: Understand CNAME record purpose
CNAME points your domain to Firebase Hosting's server address.Step 2: Effect after DNS propagation
Once DNS updates, visiting www.example.com loads your Firebase hosted site.Final Answer:
Users will see your Firebase hosted website at www.example.com -> Option BQuick Check:
CNAME to Firebase = site loads correctly [OK]
- Expecting DNS error after correct CNAME setup
- Thinking users get Firebase console page
- Assuming default Firebase page shows instead
Solution
Step 1: Check domain verification requirement
Firebase requires domain ownership verification before serving your site.Step 2: Effect of missing verification
If verification is missing, Firebase will not serve your site on the custom domain.Final Answer:
You forgot to verify domain ownership by adding the required DNS record -> Option AQuick Check:
Missing verification = site won't load [OK]
- Confusing billing with domain verification
- Thinking authentication affects domain setup
- Using wrong DNS record type for verification
example.com and www.example.com to serve your Firebase hosted site securely. Which is the best approach?Solution
Step 1: Add both domains in Firebase Hosting
Firebase requires each domain to be added and verified separately.Step 2: Verify ownership and set DNS for both
You must verify both domains and configure DNS records to point to Firebase Hosting.Step 3: Ensure HTTPS works on both domains
Firebase provisions SSL certificates for each verified domain to serve securely.Final Answer:
Add both domains in Firebase Hosting, verify ownership for both, and set DNS records accordingly -> Option AQuick Check:
Both domains added and verified = secure site on both [OK]
- Assuming Firebase auto-serves unadded domains
- Skipping verification for one domain
- Using CNAME incorrectly for apex domain
Ready to prove it?
Pass the test and this pattern moves unknown
