UUID vs INT for Primary Keys Making the Right Choice

Serghei Pogor
7 min readJul 4, 2024

Ok, so just to clarify from the beginning, this article is NOT advice or a guide on how to use and integrate database structure for your own projects. Its project has its own requirements and its own way is unique so, something for a project is GOOD but for another project, the same will be considered as BAD.

Powered by DALL·E 3

I just want to mention here from my experience what I learned, why I decided to switch to another type for the primary key, and why I personally consider it the best one for all my projects or at least for projects for which I'm involved as a Technical Lead.

So let's start with the beginning…

Not so long time ago, all apps were using only INT as primary keys. So basically each first column of any table in the database was an incrementing integer and pretty much is clear why its was used by everyone. With INT it's very easy to work, I mean it's just a number that is easy to remember… for example, you have to check something for a specific user, just by ID INT it's the fastest way to search, it's easy to remember and use.

Because of the size of INT if compared with UUID(4 bytes vs 16 bytes) of course it's clear that with INT you get faster indexing and searching within the database, and improved performance.

--

--

Serghei Pogor
Serghei Pogor

Written by Serghei Pogor

Good code is its own best documentation

No responses yet