网站内容和成员数据库ID [关闭]

Why are some websites programmed to start member ids at 1 where as some websites start off the member ids like 30000000000000000 or even a random hash?

For example, popular forum software such as vbulletin, invision power board, xenforo, etc have their members ids starting at 1. Then you look at steam for example, take a look at a profile and look at that huge member id.

I've also noticed that some websites use uuids for basically member ids. Like mojang (yes, I know stay with me). They later on added a UUID to each account.

What are the benefits of each one? Wouldn't starting at the id of 1 use less database storage?

  1. Steam IDs are from 0x0110000100000001 to 0x01100001FFFFFFFF, always 17 digits long.

    It is a steam64, also there are steam2, steam3 and steam32 versions made in different times. It includes more data than just serial number, like "the universe" number it belongs. Also my guess is that it may include region, country and other additional data.

    On top of Steam ID there are Account ID, Community ID and others which are also different in length - that fact only confirms that length is chosen on purpose.

  2. For ordinary software like forums and web-sites there is usually no need to do such complicated IDs and for optimization and simplicity ordinary incrementing serial number is used.

  3. But sometimes UUID and other tricky hashes or huge random numbers are to be used. For example such approach will help to avoid stealing users list by crawling from 1 to N (where N is latest registered user's ID) or allow to avoid a time/ID-incremental atacks based on knowledge which ID will be next.

  4. Other reason why huge random numbers may be used is by their magic property to be evenly distributed between MIN and MAX values. It may help to mathematically arrange them between N servers with ServerNumber=ID/((MAX-MIN)/NumberOfServers) formula without any additional effort.

  5. And one more case to think about is situation where there are more than one server may create a new user: if ID will be simply incremental the possibility that two servers will try to create user with same ID (current ID+1) is a real thing. But when you have random ID or UUID/GUID your chance to collide are going to zero.

So, yes, 1++ IDs are most convenient to work for, but there are also many cases where other approaches will have huge benefit for your software.

I hope you enjoyed.