DEV Community

Cover image for Benchmark: Snowflake vs UUIDv4

Benchmark: Snowflake vs UUIDv4

José Thomaz on February 17, 2024

This benchmark compares the performance of Snowflake and UUID. It was built using Go, Docker, SQLx, and PostgreSQL. The graphs below were generate...
Collapse
 
dagnelies profile image
Arnaud Dagnelies

I actually consider whether they take a few microsecond or not to be almost irrelevant. The UUID have the benefits to be standardized and to be true random. I guess that's why the time it takes to generate them varies so much, because it depends on system entropy as you said. This is very important though to have secure non-guessable IDs. I would fear that be getting a few snowflake IDs, you could find out the random seed and find out the upcoming IDs. Being able to guess them can bring trouble in terms of attacks / vulnerabilities. Or are they secure?! If you just want a (pseudo-)random number, I guess you could just use the standard random number generator your programming language has, it's even faster. Snowflake is a special solution for a highly specific problem. I think putting a few words of introduction would have been, otherwise people reading this benchmark might think it's an alternative to UUIDs.

Collapse
 
josethz00 profile image
José Thomaz

Yes! That's a micro-optimization/benchmark, I forgot to point that, will edit the article. For big systems it would surely make the difference in performance and disk usage, although it probably won't be your main bottleneck.

Btw, I still think that's better to use Snowflakes than the standard random number generator of your language. Inside a snowflake id, you have a timestamp part, a sequence, and a random number.

Collapse
 
j0nimost profile image
John Nyingi • Edited

Snowflake also shines when you want to use sharding on your DB. Nevertheless, I love seeing the benchmarks.