Unique ID Generation on the Cloud

Go To StackoverFlow.com


I'm looking for a simple but robust solution for provisioning unique Part Numbers. I have been thinking about using GUID to identify requests from different clients (desktops, phones, etc.) and then assigning PNs sequentially based on insert date-time of the request GUIDs.

Questions: Is SQL Azure the right service to use? Is there a standard approach to this?


2012-04-03 21:28
by Carlo Mendoza


This has little to do with being "on the Cloud", but rather is a general distributed computing question.

There's not enough information in your question to fully understand your requirement, but what I'm gathering is that you need to assign a unique number to consumers of a service that request a Part Number.

A first thought is that a GUID is a number (128 bits long). Can't you just generate a GUID whenever you need to assign a Part Number? If needed, you could hash the GUID into, say, an unsigned long (City Hash is my favorite 64-bit hash for that type of application) with very, very little risk of hash collision unless you're dealing with billions of part numbers. If you feel the urge to hash into a 32-bit number, have a look at the Birthday Problem. Hash collisions will be far more frequent than you might think with only 32 bits.

If you must assign a sequential number, you necessarily introduce a serialization point in your processing. You will need some service (could be an Identity column on a DB table) that counts individual part number requests and assigns the next-larger number.

If you generally desire smallish numbers but they do not necessarily have to be sequential, you could allow each server that might process such a request to manage it's own range of numbers (e.g. a given server could "check out" a block of 1000 part numbers from a central service, assign them until they are used up, and then "check out" a new block of numbers). This does not guarantee that all numbers currently assigned are sequential, as multiple servers could assign numbers at different rates. Also, if you don't properly manage application crashes, you can "lose" part of a number block that was checked out but not completely assigned.

2012-04-03 21:45
by Eric J.
Is there a c# implementation of CityHash out there - JMarsch 2012-04-03 22:07
@JMarsch: Out there, no, but it's very straightforward to port from C++. I did that for a former employer in about an hour - Eric J. 2012-04-03 22:54
@EricJ.: I mention the cloud because we don't have servers that can guarantee availability that come close to a cloud solution. We have guys that are out and about needing to generate PNs for quotes. And I think we are somewhat on the same page. My initial thoughts are to insert request GUIDs in to the database and PNs are subsequently generated - Carlo Mendoza 2012-04-04 20:36
@EricJ.: To add, we won't have billions of part numbers, and the PNs are probably no longer than 10 digits - Carlo Mendoza 2012-04-04 20:41


you might wanna have a look a this one: SnowMaker – a unique id generator

2012-04-04 05:44
by JuneT
I'm looking into that too. Thank - Carlo Mendoza 2012-04-04 20:39
SnowMaker, with some modifications to run on Azure Mobile Services (mostly involves including the Mobile Services dlls instead of the ones included in the project) is working well for me - Timothy Lee Russell 2015-03-10 01:38