Take the 2-minute tour ×

I am writing a small web application for Windows Azure, which should use the blob storage for, obviously, storing blobs.

Is there a function or a way to automatically generate a unique name for a blob on insert?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

You can use a Guid for that:

string blobName = Guid.NewGuid().ToString();
share|improve this answer
add comment

In addition to what Sandrino said (using GUID which have very low probability of being duplicated) you can consider some third-party libraries which generate conflict-free identifiers example: Flake ID Generator


Herve has pointed out very valid Azure Blob feature which should be considered with any blob names, namely, Azure Storage load balancing and blobs partitioning.

Azure keeps all blobs in partition servers. Which partition server should be used to store particular blob is decided on the blob container and the blob file name. Unfortunately I was not able to find and documentation describing algorithm used for blobs partitioning.

More on Azure Blob architecture can be found on Windows Azure Storage Architecture Overview article.

share|improve this answer
add comment

There is nothing that generates a unique name "on insert"; you need to come up with the name ahead of time.

When choosing the name of your blob, be careful when using any algorithm that generates a sequential number of some kind (either at the beginning or the end of the name of a blob). Azure Storage relies of the name for load balancing; using sequential values can create contention in accessing/writing to Azure Blobs because it can prevent Azure from properly load-balancing its storage. You get 60MB/Sec on each node (i.e. server). So to ensure proper load-balancing and to leverage 60MB/Sec on multiple storage nodes you need to use random names for your blobs. I typically use Guids to avoid this problem, just as Sandrino is recommending.

share|improve this answer
that's a very valid point (+1). BTW, do you have references to an article describing algorithm used by the partition layer to distribute blobs across blob storage nodes? I think it would be very beneficial from question point of view. –  Tom Jan 16 '13 at 10:21
No I don't; there used to be an MS article about the fact that this was going on (without underlying details), but I can't find it anymore... If I find the link I will post. You can't control what MS does with partitioning, and it is likely to be dynamic based on usage of your data and other tenant data. So what I do is that I treat the underlying access layer as non deterministic. –  Herve Roggero Jan 17 '13 at 22:45
that's fair enough. I only found a link to a blog describing Azure Storage architecture which is as follows: blogs.msdn.com/b/windowsazurestorage/archive/2010/12/30/… –  Tom Jan 20 '13 at 17:35
Ah! Found the link: blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/… - Go about half way; there is a section about "key selection". Although the topic is Azure Table, the logic remains the same with Blob Names because that's how load balancing is done. Basically, the "append only" pattern should be avoided. –  Herve Roggero Jan 20 '13 at 23:14
add comment

Your Answer


