Custom domains in Supabase - Time & Space Complexity
When setting up custom domains in Supabase, 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 domains affects the total operations needed to configure them.
Analyze the time complexity of adding multiple custom domains to a Supabase project.
// Example: Adding multiple custom domains
const domains = ['example1.com', 'example2.com', 'example3.com'];
for (const domain of domains) {
await supabase.functions.createCustomDomain({
domain: domain,
projectId: 'project-id'
});
}
This code adds each domain one by one to the Supabase project by calling the API for each domain.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: API call to create a custom domain for each domain.
- How many times: Once per domain added.
Each new 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 operations grows in a straight line as you add more domains.
Time Complexity: O(n)
This means the time to add custom 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, so the total time increases with each additional domain.
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 batch adding of multiple domains in one call? How would the time complexity change?"