Search code examples
sqlprimary-keynatural-key

Unique identifiers for users


If I have a table of a hundred users normally I would just set up an auto-increment userID column as the primary key. But if suddenly we have a million users or 5 million users then that becomes really difficult because I would want to start becoming more distributed in which case an auto-increment primary key would be useless as each node would be creating the same primary keys.

Is the solution to this to use natural primary keys? I am having a real hard time thinking of a natural primary key for this bunch of users. The problem is they are all young people so they do not have national insurance numbers or any other unique identifier I can think of. I could create a multi-column primary key but there is still a chance, however miniscule of duplicates occurring.

Does anyone know of a solution?

Thanks


Solution

  • I would say that for the time being keep an auto increment for the user ID.

    When you do have that sudden rush of millions of users, then you can think about changing it.

    In other words, solve the problem when you have it. "premature optimization is the root of all evil.".

    To answer the question - some auto increments will allow you to seed the auto increment, so you can get different auto increments on the different nodes. This will avoid the problem, while still allowing use of an auto increment.