0

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.

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the info, but unfortunately I'm specifically curious about StackOverflow's implementation because not only are they able to generate a unique integer, but its length isn't as massive as any kind of uuid implementation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.