Uploading and downloading objects in AWS - Time & Space Complexity
When working with cloud storage, it is important to understand how the time to upload or download files changes as the number of files grows.
We want to know how the number of upload or download actions affects the total time taken.
Analyze the time complexity of the following operation sequence.
// Upload multiple files to S3
for (let i = 0; i < files.length; i++) {
s3.putObject({ Bucket: 'my-bucket', Key: files[i].name, Body: files[i].data }).promise();
}
// Download multiple files from S3
for (let i = 0; i < files.length; i++) {
s3.getObject({ Bucket: 'my-bucket', Key: files[i].name }).promise();
}
This sequence uploads and then downloads each file one by one from an S3 bucket.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Each
putObjectandgetObjectAPI call to upload or download a single file. - How many times: Once per file, so the number of calls equals the number of files.
As the number of files increases, the total number of upload and download calls grows directly with it.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 20 (10 uploads + 10 downloads) |
| 100 | 200 (100 uploads + 100 downloads) |
| 1000 | 2000 (1000 uploads + 1000 downloads) |
Pattern observation: The total operations increase in a straight line as the number of files grows.
Time Complexity: O(n)
This means the time to upload and download grows directly in proportion to the number of files.
[X] Wrong: "Uploading or downloading many files takes the same time as just one file because the cloud is fast."
[OK] Correct: Each file requires a separate upload or download action, so more files mean more work and more time.
Understanding how upload and download times grow helps you design efficient cloud storage solutions and explain your reasoning clearly in discussions.
"What if we uploaded all files in parallel instead of one by one? How would the time complexity change?"