Environment variables and secrets in Supabase - Time & Space Complexity
We want to understand how the time to access environment variables and secrets changes as the number of these items grows.
How does the system handle more secrets or variables when your app needs them?
Analyze the time complexity of the following operation sequence.
// Fetch multiple environment variables and secrets
const secrets = ["API_KEY", "DB_PASSWORD", "SERVICE_TOKEN"];
const values = [];
for (const key of secrets) {
const value = await supabase.functions.getSecret(key);
values.push(value);
}
return values;
This code fetches several secrets one by one from Supabase's secret storage.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling
supabase.functions.getSecret(key)to fetch each secret. - How many times: Once for each secret in the list.
Each secret requires one separate call, so the total calls grow directly with the number of secrets.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of calls increases one-to-one with the number of secrets requested.
Time Complexity: O(n)
This means the time to fetch secrets grows linearly as you ask for more secrets.
[X] Wrong: "Fetching multiple secrets happens all at once, so time stays the same no matter how many secrets."
[OK] Correct: Each secret fetch is a separate call, so more secrets mean more calls and more time.
Understanding how secret fetching scales helps you design apps that stay fast and secure as they grow.
"What if Supabase allowed fetching all secrets in one batch call? How would the time complexity change?"