views:

70

answers:

4

Hello All

I am planning on using sequential guids as primary keys/uuids as detailed in the post below

http://stackoverflow.com/questions/170346/what-are-the-performance-improvement-of-sequential-guid-over-standard-guid/170363#170363

I am wondering if there are any gotchas as far as generating these guids across multiple web servers in a web farm environment. I suspect the chances of collision are impossibly low but the fact that the mac address of the web server/timestamp would doubtless be involved in generating these guids gives me pause. I wonder if the possibility exists in a high traffic website the ordering would be messed up and the benefit of using sequential guids might be lost.

Please let me know what your experience is.

For what it is worth, my environment is ASP.NET 3.5, IIS 7 using Oracle 11g. Incidentally, what is the data type I should use for guids in Oracle? I know that Sql Server has "uniqueidentifier"

Thanks for your advice -Venu

A: 

To ensure that you have unique GUIDs only 1 server can be the creator of said GUIDs.

If memory serves, Oracle doesn't support the creation of MS's "Guid for OLE" but you should be able to generate something highly similar utilizing this: RAWTOHEX(SYS_GUID())

Alternatively, you could have a separate application residing on a single server that is solely responsible for generating GUIDs (for example, call a web service located at a specific server, whose sole purpose is to generate and return GUIDs.

Finally, GUIDS are not sequential. Even if you generate one right after another, they won't increment in the exact same fashion as an integer (i.e. that last digit won't go from C-D in one step). Sequencing requires integers or some other numeric data type.

Stephen Wrighton
Thx. If I have a central server for serving guids, isn't that defeating the point of distribution? I am hoping there is a way around this
A: 

Guid for Oracle

SQLMenace
A: 

You might want to take a look at how NHibernate's Guid Comb generator works. I have never heard of a collision.

Daniel Auger
I did look into it. Jimmy Nilsson's states that the possibility of collision is zilch if records insertions are atleast 300 ms apart.Unfortunately, the traffic we am expecting is much higher than that
A: 

Because I was the creator of the post you're referring to I can answer to it.

We're using the C# code shown in the post (without the modification of ordering detailed in one of the reply, that I feel could improve performance another little bit) in web farms with from 2 to 8 application servers and never had problems of concurrency, I believe that the SequentialGuid function implemented in the Windows core DLLs already takes care of creating different guid on different machines.

In database operation having different machines inserting different Guids means that each different application server in the web farm will write data that will reside on specific regions of the database (i.e. an application server will write guid starting with 12345 and the other one with guid starting with 62373) and so the update of indexes still works efficiently because page splits do not happens very frequently (or never).

So, from my experience, no specific problem happens if you use the same strategy to generate Guids that I outlined in my original message also if you're working in web farm enviviroment if you use the proper method to generate the Guids.

I would avoid in any way to create Guid from code and also to create Guid in a central manner.

Regarding data type we used char(36) because we like to waste a lot of space! Joke aside we decided to use a long and verbose way to write data because having data in a clear format ease a lot the maintenance, but you can use Oracle GUID or simply a RAW(16) data type (they're basically the same) and spare 20 bytes of for each row. To make browsing and editing of data easier you can provide your customer a couple of function to code and decode raw guid data so that the textual representation of the guid is seen.

massimogentilini