A webapp I am speccing out is going to need to be horizontally scalable, and will require a pair of MySQL servers from the start (perhaps rising to more than one soon after launch). As an auto-increment primary key is not suitable, I was wondering what alternatives people use.
Something with the date in makes the most sense, but if you go down to the millisecond level and assume a three-digit server ID it's a very big number:
sssyymmddhhmmssmicros
or 001110510143622123456
for right now - plus you could perhaps do with another number at the beginning to simplify the leading zeros (datacentre ID, perhaps).
Epoch time shortens it, but only a little.
What else is there?
I think what you're looking for is UUID (Universal Unique Identifier). In MySQL you can generate UUID's whith the function uuid().
SELECT uuid();
An UUID looks like this 8cb1764a-7b0d-11e0-aaa7-00270e0f8070 ... I know! it's very long but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With