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?
Practice
Solution
Step 1: Understand block blob usage
Block blobs are designed to store large files uploaded in blocks and allow updating by replacing blocks.Step 2: Compare with other blob types
Append blobs are for append-only operations, and page blobs are optimized for random read/write operations, not block uploads.Final Answer:
Block blob -> Option CQuick Check:
Block blob = large files in blocks [OK]
- Confusing append blob with block blob
- Thinking page blob is for block uploads
- Selecting non-existent blob types
Solution
Step 1: Identify correct blob type syntax
The Azure CLI uses --type AppendBlob to create an append blob.Step 2: Verify other options
BlockBlob and PageBlob are valid types but not for append blobs; FileBlob is invalid.Final Answer:
az storage blob create --container-name mycontainer --name myappendblob --type AppendBlob -> Option AQuick Check:
Append blob creation uses --type AppendBlob [OK]
- Using BlockBlob type for append blobs
- Using PageBlob type for append blobs
- Using invalid blob type names
blob_client = container_client.get_blob_client('myblob')
blob_client.upload_blob(data, blob_type='PageBlob')
What will happen if the data size is not a multiple of 512 bytes?Solution
Step 1: Understand page blob requirements
Page blobs require data size to be a multiple of 512 bytes for alignment.Step 2: Analyze upload behavior
If data size is not aligned, the upload will fail with an error about size alignment.Final Answer:
Upload will fail with an error about data size alignment -> Option AQuick Check:
Page blob data size must be multiple of 512 bytes [OK]
- Assuming automatic padding of data
- Thinking upload truncates data silently
- Believing blob type auto-conversion occurs
Solution
Step 1: Identify append blob usage
Append blobs require using append_block to add data without overwriting.Step 2: Analyze the overwrite behavior
Using upload_blob with overwrite=True replaces existing data, not appends.Final Answer:
Using upload_blob with overwrite=True instead of append_block method -> Option DQuick Check:
Append blobs append with append_block, not upload_blob overwrite [OK]
- Confusing append_block and upload_blob methods
- Creating wrong blob type
- Using page blob APIs on append blobs
Solution
Step 1: Identify requirements for VM disks
VM disks need frequent random read/write with low latency and page-level updates.Step 2: Match blob type to requirements
Page blobs support random read/write operations in 512-byte pages, ideal for VM disks.Step 3: Exclude other blob types
Block blobs are for large uploads, append blobs for append-only logs, and file blob is not a valid Azure blob type.Final Answer:
Page blob, because it supports random read/write with 512-byte pages -> Option BQuick Check:
VM disks use page blobs for random read/write [OK]
- Choosing block blob for VM disks
- Confusing append blob with page blob
- Selecting non-existent file blob type
Ready to prove it?
Pass the test and this pattern moves unknown
