Home / Go package for better guid generation edit

The need to generate a globally unique identifier comes up often.

The way described in RFC 4122 is popular but it can be done better.

I wrote betterguid Go package that does it better.

Unique id generated by this package:

  • is a 20 character string, safe to include in urls (no need for escaping)
  • consist of 8 bytes of timestamp (millisecond precision) and 9 bytes of random data
  • sorts lexicographically
  • 72-bits of random data ensures IDs won’t collide with IDs generated by other clients
  • are monotonically increasing even within the same timestamp

You can read a longer description of the algorithm.

My implementation is based on this JavaScript code.

Related: comparison of 7 Go libraries for unique id generation.

Go to index of articles.

Share on