Search code examples
c#windows-server-2008windows-server-2012

Can I rely on a GUID strategy to create unique folders on a SAN shared by multiple cloned Windows servers?


[Note to those reaching for the duplicate button: It is July 2017. There are near duplicates to this question from the past, however part of the reason for raising the question is to illuminate whether the answer has changed over time as technology has changed. Also, this question is more about how to create reliably unique folders at speed on a SAN from multiple cloned web servers. I cannot find a duplicate of this question but would be happy to be pointed at a recent example.]

Question - is there a pragmatic potential for multiple cloned MS 2008+ servers to produce the same GUID value?

Context:

I am investigating the creation of unique folders by multiple servers on a shared SAN. Imagine a web farm with many web servers using the same file storage. [Please refrain from the 'Why do it like that' responses.]

This is a C# / Dot Net based solution running on MS Windows server 2008+.

The natural tool to reach for is the GUID as it gives minimal overhead assuming no physical check for a folder of the given GUID on disk (because that would introduce time-costly network and disk reading overhead).

However, a GUID is only viable IF the GUID is actually unique cross-servers.

Research:

In this question from 2008, the poster asked about the uniqueness of a UUID / GUID.

In this question from 2009 the performance of MS GUID's was discussed.

I know of old that the 'random' functions in computers are seeded and therefore not random. I read that the GUID was originally generated partly from the device MAC address and therefore would have a firm chance of uniqueness. But then I read that this use of the MAC address was retired, which leads me to go back to considering the old 'rnd()' seeding issue or its equivalent and ponder the impact of uniqueness in practical terms across multiple servers.

And for those proponents of the stats related to UUID's, a couple of responses I found during research mention the Birthday Paradox. I wonder what practical impact this has across multiple servers.

Potentially useful question on Path.GetRandomFileName v's Guid.NewGuid.

Dot Net Pearls has an interesting article on performance of the algorithm behind Path.GetRandomFileName.


Solution

  • During my research I found a lot of cases of people talking about the probability of a GUID clash being vanishingly small. But since I keep buying lottery tickets I guess I am convinced that even vanishingly small chances can occur.

    As a reminder, my need is to have an approach for multiple Windows servers to be creating unique folders on a shared SAN. This questions was about the use of a guid alone, and I conclude, whilst accepting the slim chance, that a clash could occur.

    My approach from here will be to assign each server a unique server id in its config, and to have that id pre-pended to the folder name. I will then use the Dot Net

    Path.GetRandomFileName()
    

    function to generate the second component of the folder names. This, I believe, will give me a 100% unique folder names, though the instance-rollout script will be a bit more involved. See this link for info on GetRandomFileName().