> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/improvements-tips-module/tips/uuid.md).

# 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 immense amount of possible, distinct UUIDs (2^128 or 340,282,366,920,938,463,463,374,607,431,768,211,456). 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](https://blog.boot.dev/clean-code/what-are-uuids-and-should-you-use-them/) by **Lane Wagner** (blog) as an additional study.

If you are interested in using UUIDs in the system, TypeORM allows to map an id as a UUID through the following way:

```typescript
@PrimaryGeneratedColumn('uuid')
id: string;
```

Also, Class Validator allows to validate a UUID through the <mark style="color:blue;">`@IsUUID()`</mark> decorator.
