Blob storage (block, append, page) in Azure - Time & Space Complexity
When working with Azure Blob Storage, it's important to understand how the time to upload or modify data changes as the size or number of blobs grows.
We want to know how the number of operations or API calls increases when handling block, append, or page blobs.
Analyze the time complexity of uploading data using block blobs.
// Upload a large file as blocks
var blockIds = new List<string>();
int i = 0;
foreach (var block in fileBlocks) {
string blockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(i.ToString()));
await blobClient.StageBlockAsync(blockId, new MemoryStream(block));
blockIds.Add(blockId);
i++;
}
await blobClient.CommitBlockListAsync(blockIds);
This sequence uploads a file by splitting it into blocks, uploading each block, then committing the list to form the blob.
Look at what repeats as the input grows:
- Primary operation: Uploading each block with
StageBlockAsync. - How many times: Once per block, so the number grows with the number of blocks.
- Commit operation:
CommitBlockListAsyncruns once after all blocks upload.
As the file size grows, the number of blocks increases, so the number of upload calls grows too.
| Input Size (blocks) | Approx. API Calls |
|---|---|
| 10 | 10 block uploads + 1 commit = 11 |
| 100 | 100 block uploads + 1 commit = 101 |
| 1000 | 1000 block uploads + 1 commit = 1001 |
Pattern observation: The number of upload calls grows directly with the number of blocks.
Time Complexity: O(n)
This means the time to upload grows linearly with the number of blocks you upload.
[X] Wrong: "Uploading a large file is just one API call, so time stays the same no matter the size."
[OK] Correct: Large files are split into many blocks, each requiring a separate upload call, so time grows with file size.
Understanding how upload operations scale helps you design efficient cloud storage solutions and explain your reasoning clearly in interviews.
What if you used append blobs instead of block blobs? How would the time complexity change when adding data?