

Well, we need to store a user ID, so we just start storing the user’s ID in that separate database as a kind of foreign key. For example, there may be a separate database that stores social media posts and we need to know which user made the posts. That may be fine for a while, but now imagine that we introduce more services into our backend architecture. So the first user will have the ID “1”, the next will be “2”, and so on. Each user has a primary key, and like many databases, that primary key is just an integer. One of the tables in that database is the “users” table. Let’s pretend we have a web application with a single database. Let’s take a real-world example and analyze why using UUIDs can make our lives easier. UUIDs used by completely unrelated companies or organizations can be referenced together without duplication. The main advantage of using UUIDs is that you can create a UUID and use it to identify something, such as a row in a database, with near certainty that the identifier will not exist in another row in your system or anyone else’s. On v, my platform for developers who want to learn back-end engineering, I use UUIDs as the primary key for all database records.

It reduces the chances of future ID conflicts and makes building a distributed architecture much easier. In short, if you don’t have extremely strict memory and performance requirements, I’d recommend using UUIDs instead of integer IDs. No other ID in existence should be the same as yours. By using UUIDs, you ensure that your ID is not just unique in the context of a single database table, but is unique in the universe.
#Mysql uuid not unique code#
A universally unique identifier (UUID) is a 128-bit format for creating IDs in code that has become popular in recent years, especially when it comes to database keys. If the site is a social media platform, then each post will also have a unique ID. For example, each user on a website will its own ID. In the context of back-end web development, an ID is just a unique identifier for a record of data.
