0
votes

I have an Excel file hosted on Azure blob storage for logging usage statistics pertaining to a website. The application accessing the Azure storage is a Web API and makes use of blob reference and memory stream to write data back and forth from the blob asynchronously.

Does the asynchronous operation of writing the data back to the blob being handled as part of the reader writer problem e.g. lets say originally there were 10 records and now two users are accessing the blob at the same time. Will the blob be updated to have 12 records in the end?

1

1 Answers

1
votes

Does the asynchronous operation of writing the data back to the blob being handled as part of the reader writer problem e.g. lets say originally there were 10 records and now two users are accessing the blob at the same time. Will the blob be updated to have 12 records in the end?

Assuming both users read the blob at the same time, the last one to update the blob will overwrite the changes done by the other user. So User A and B read the blob. Now User A updates the blob and shortly after that User B updates the blob. In this case, changes done by User A will overwritten by User B.

You could prevent this behavior by specifying conditional headers in your update request. This is facilitated by a number of things but most commonly ETag property on the blob is used. In this case, both User A and B will read the blob. Both of them have same value for blob's ETag. Now User A updates the blob conditionally (i.e. telling Azure Storage Service to update the blob only if ETag value presented during update matches the most recent ETag value of the blob). Since the blob has not been updated by anyone else, this operation will succeed. Now User B also updates the blob conditionally however this update would fail as when User A updated the blob, its ETag value has changed. In this case User B needs to fetch the blob's contents again and apply the changes and save the blob again.

Another option is to make use of Append Blobs if all the time users are adding data to the end of the blob. Append Blobs do not have this problem.