Generating unique user Ids for new users after sign-up [duplicate]
Possible Duplicate:
Designing Unique Keys(Primary Keys) for a heavily denormalized NoSQL database
I am looking for a way to generate unique UserIds/ keys to store the data of the new users, after they sign up on my application.
One option is to get the randomly generated UUID, but these are 16 bytes long (and since I am using Cassandra, a NoSQL database which involves heavy denormalization), I am concerned whether I would be wasting lot of disk space, RAM and other resources if the key could be generated in smaller sizes.
The main inspiration behind trying to reduce the size of the userId is that, I am using userIds for heavy denormalization. UUIDs are 16 bytes long, but I can also 开发者_运维问答have a unique Id in just 4 bytes(if I use a counter that keeps track of no of users on my application ), and Since sign-up is just a one time process, it makes sense to try cut down the space requirements, if it is feasible "without any downsides"(!?).
I am using userIds to attach to Id of other data of the user on my application. This way I could drastically cut down the space requirements.
What could be the ways to generate unique Ids for new users ?
You said that you might use 4 instead of 16 bytes per user. This will save you 12 bytes per user what saves you 1.2 Giga bytes per 100 million users. I am sure that you can afford such storage for that many users.
But if you use this user ID in way that it is not exposed to user (for instance in URL) increasing numbers could be just ok. Other way if this numbers is exposed to user and can manipulate it have in mind protection against birthday attack http://en.wikipedia.org/wiki/Birthday_attack
精彩评论