The problem with UUIDs is that they are very big in size and don’t index well.
The chances of the same UUID getting generated twice is negligible. UUIDs are 128-bit hexadecimal numbers that are globally unique.
I’ll also outline other existing solutions and discuss their pros and cons. In this article, I’ll share a simplified version of the unique ID generator that will work for any use-case of generating unique IDs in a distributed environment, not just sharded databases. So I looked at various existing solutions for this, and finally wrote a simple 64-bit unique ID generator that was inspired by a similar service by Twitter called Twitter snowflake. When you’re working with a single MySQL database, you can simply use an auto-increment ID as the primary key, But this won’t work in a sharded MySQL database. While working on this application, I needed to generate unique IDs that could be used as the primary keys in the tables. I was recently working on an application that had a sharded MySQL database. Generating unique IDs in a distributed environment at high scale.