So I'm currently building an android app and for the login and registration process, I'm using Firebase. Everything else will be stored in my server/database. My question is, would it be a good practice to use the Firebase UID (a varchar) as my primary key in my own database?
Or would it be better to use auto-increment int as the primary key, and simply store the UID in another column with a unique constraint?
I always thought that it would be a bad practice to use varchar but then again, I see that postgresql has the UUID function which I believe is meant for this exact purpose??
Any thoughts?
CodePudding user response:
The UID is generated by Firebase and not by you (or your database). I would therefore not use it as a primary key in your database.
Also the UUID is not a varchar in postgres. The only real benefit of using an UUID (in my opinion) is that it is unique also outside of your environment. This might be beneficial if you want to share your ids with other applications.
The data type uuid stores Universally Unique Identifiers (UUID) as defined by RFC 4122, ISO/IEC 9834-8:2005, and related standards. (Some systems refer to this data type as a globally unique identifier, or GUID, instead.) This identifier is a 128-bit quantity that is generated by an algorithm chosen to make it very unlikely that the same identifier will be generated by anyone else in the known universe using the same algorithm. Therefore, for distributed systems, these identifiers provide a better uniqueness guarantee than sequence generators, which are only unique within a single database.