Creating storage buckets in Supabase - Performance & Efficiency
When creating storage buckets in Supabase, it's important to know how the time to create them changes as you add more buckets.
We want to understand how the number of buckets affects the total work done.
Analyze the time complexity of the following operation sequence.
const bucketNames = ["photos", "videos", "documents"];
for (const name of bucketNames) {
const { data, error } = await supabase.storage.from('bucket').createBucket(name, {
public: false
});
if (error) {
console.error(error);
}
}
This code creates multiple storage buckets one by one with given names.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling
supabase.storage.createBucket()API to create each bucket. - How many times: Once for each bucket name in the list.
Each new bucket requires one API call, so the total work grows directly with the number of buckets.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls grows linearly as you add more buckets.
Time Complexity: O(n)
This means the time to create buckets grows in direct proportion to how many buckets you want to create.
[X] Wrong: "Creating multiple buckets happens all at once, so time stays the same no matter how many buckets."
[OK] Correct: Each bucket creation is a separate API call that takes time, so more buckets mean more calls and more total time.
Understanding how operations scale with input size helps you design efficient cloud workflows and shows you can think about resource use clearly.
"What if we created all buckets in parallel instead of one after another? How would the time complexity change?"
Practice
Solution
Step 1: Understand storage bucket purpose
A storage bucket is used to hold and organize files securely in the cloud.Step 2: Compare options
Options B, C, and D describe other services not related to file storage.Final Answer:
To organize and protect files in the cloud -> Option DQuick Check:
Storage bucket = organize and protect files [OK]
- Confusing buckets with databases
- Thinking buckets run code
- Assuming buckets send emails
photos in Supabase?Solution
Step 1: Recall correct method signature
The methodcreateBuckettakes the bucket name and an options object with apublicboolean.Step 2: Identify correct privacy option
Settingpublic: falsemakes the bucket private. Other options use incorrect keys.Final Answer:
supabase.storage.createBucket('photos', { public: false }) -> Option BQuick Check:
Use public: false for private bucket [OK]
- Using wrong option keys like isPublic or private
- Setting public: true for private buckets
- Confusing access property with public
const { data, error } = await supabase.storage.createBucket('docs', { public: true });
console.log(data);Solution
Step 1: Understand createBucket return value
The method returns an object with bucket info if successful, including name and public status.Step 2: Analyze the code output
Sincepublic: trueis valid,datawill contain bucket details, not an error or boolean.Final Answer:
An object with bucket details including name 'docs' and public true -> Option CQuick Check:
createBucket returns bucket info object [OK]
- Thinking it returns only true/false
- Assuming it throws error for public option
- Expecting no return value
await supabase.storage.createBucket('files', { public: 'no' });What is the likely cause?
Solution
Step 1: Check option types
Thepublicoption expects a boolean true or false, not a string.Step 2: Identify error cause
Passing 'no' as a string causes a type error. Bucket name and await usage are correct.Final Answer:
The 'public' option must be a boolean, not a string -> Option AQuick Check:
public option = boolean, not string [OK]
- Passing 'yes' or 'no' as strings
- Ignoring await keyword
- Using invalid bucket names
images and one private named backups. Which code correctly does this?Solution
Step 1: Set correct privacy flags
Public bucket needspublic: true, private bucket needspublic: false.Step 2: Verify method calls
await supabase.storage.createBucket('images', { public: true }); await supabase.storage.createBucket('backups', { public: false }); correctly sets these flags. await supabase.storage.createBucket('images', { public: false }); await supabase.storage.createBucket('backups', { public: true }); reverses them. await supabase.storage.createBucket('images'); await supabase.storage.createBucket('backups'); omits privacy, defaulting to private. await supabase.storage.createBucket('images', { access: 'public' }); await supabase.storage.createBucket('backups', { access: 'private' }); uses invalid keys.Final Answer:
await supabase.storage.createBucket('images', { public: true }); await supabase.storage.createBucket('backups', { public: false }); -> Option AQuick Check:
Public = true, Private = false [OK]
- Mixing up public true/false
- Omitting privacy option
- Using wrong option keys like access
Ready to prove it?
Pass the test and this pattern moves unknown
