Need a smaller alternative to GUID for DB ID but still unique and random for URL

Raymond Chen has a good article on why you shouldn’t use “half a guid”, and offers a suitable solution to generating your own “not quite guid but good enough” type value here:

GUIDs are globally unique, but substrings of GUIDs aren’t

His strategy (without a specific implementiation) was based on:

  • Four bits to encode the computer number,
  • 56 bits for the timestamp, and
  • four bits as a uniquifier.

We can reduce the number of bits to make the computer unique since the number of computers in the cluster is bounded, and we can reduce the number of bits in the timestamp by assuming that the program won’t be in service 200 years from now.

You can get away with a four-bit uniquifier by assuming that the clock won’t drift more than an hour out of skew (say) and that the clock won’t reset more than sixteen times per hour.

Leave a Comment