Creating buckets and uploading objects in GCP - Performance & Efficiency
When working with cloud storage, it is important to understand how the time needed to create buckets and upload objects changes as you add more items.
We want to know how the number of buckets and objects affects the total work done.
Analyze the time complexity of the following operation sequence.
// Create multiple buckets and upload one object to each
for (let i = 0; i < n; i++) {
await storage.createBucket(`bucket-${i}`);
await storage.bucket(`bucket-${i}`).upload(`file-${i}.txt`);
}
This code creates n buckets and uploads one object to each bucket.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a bucket and uploading an object.
- How many times: Each operation happens once per bucket, so n times.
As the number of buckets (n) increases, the total number of create and upload operations grows directly with n.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 20 (10 creates + 10 uploads) |
| 100 | 200 (100 creates + 100 uploads) |
| 1000 | 2000 (1000 creates + 1000 uploads) |
Pattern observation: The total operations increase in a straight line as n grows.
Time Complexity: O(n)
This means the work grows directly in proportion to the number of buckets and objects you handle.
[X] Wrong: "Creating multiple buckets and uploading objects happens all at once, so time stays the same no matter how many."
[OK] Correct: Each bucket creation and upload is a separate action that takes time, so more buckets mean more total work.
Understanding how cloud operations scale helps you design efficient systems and explain your reasoning clearly in real-world discussions.
"What if we upload multiple objects to each bucket instead of one? How would the time complexity change?"