Reputation: 1235
I'm looking for a way to generate unique integer IDs for my customers, very similar to how StackOverflow/StackExchange generates one for each question. The challenge is making this number unique in a distributed system since multiple databases are used, which means that the auto increment
feature cannot work.
I have to assume that a huge site like StackOverflow/StackExchange is distributed, so I would very much like to know how it's able to generate a unique integer without any collisions.
From what I've seen, the two kinds of implementations around are Flickr's ticket server approach, but that creates a single point of failure, or Twitter's Snowflake, but that generates a 64 bit number, whereas StackOverflow's seems to be much smaller.
Upvotes: 0
Views: 79
Reputation: 52602
Your operating system most likely has some way to do this. For example, on iOS or MacOS X you just call a method in NSUUID; others will have something similar. This gives you 122 random bits. If you insist on integers, I'd split this into two 64-bit integers. Uniqueness is practically guaranteed by having 122 random bits.
Upvotes: 0