UUID

A more robust ID, one could say.

In our system, we utilized the serial id. That is, positive integers that increment after each insertion. There is another kind of id that could be employed, which is the UUID (Universally unique identifier).

Its main advantage is a virtually 100% chance that every UUID ever generated in the world is completely unique. This is due to the imense amount of possible, distinct UUIDs (2^128 or 340282366920938463463374607431768211456). So, it is practically impossible for databases' ids to collide for some reason, or someone to try to guess an id for ill-intentioned purposes.

A downside of the UUID is that it occupies more space than the normal id, even though that is not necessarily much of a problem. I leave this post as an additional study.

If you have interest in using the UUID in the system, TypeORM allows to map an id as a UUID through the following way

@PrimaryGeneratedColumn('uuid')
id: string;

Also, Class Validator allows to validate a UUID through the @IsUUID() decorator.

Last updated