Carlo Mendoza
Carlo Mendoza

Reputation: 825

Unique ID Generation on the Cloud

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?

Thanks.

Upvotes: 1

Views: 1913

Answers (2)

JuneT
JuneT

Reputation: 7860

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

Upvotes: 0

Eric J.
Eric J.

Reputation: 150108

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.

Upvotes: 7

Related Questions