I'm building a REST API, backed by MySQL. Normally for every table I will have at least one: id UNSIGNED INT NOT NULL PRIMARY KEY AUTO_INCREMENT
field as a default, but the issue with this is that it makes identifiers predictable, and tells end-users how many entries of a given resource we have, and potentially the rate of change.
I'd like my ID's to not have that issue. Instead, I would rather use something random. I've decided on using a 64bit random number, represented as a base64url string.
The way I've implemented this is adding a external_id VARCHAR(11) NOT NULL UNIQUE
to every table, keeping the id
and using the id
for all foreign keys.
As I'm doing this, I'm starting to wonder if it isn't better to just fully ditch the AUTO_INCREMENT
field and just convert my external_id
to a 64 bit INT and make this the main key used throughout my data model.
One disadvantage is that it's an extra step to convert this number to the string variant.
I'm not interested in academic purity of my data model, but I'm curious how people generally solve this issue. Do you use 2 ids?