Short, sortable, globally unique IDs for Go with no configuration
open sourceMITfree
xid is a Go library by Olivier Poitrey that generates globally unique IDs in server code with no configuration or central generator. It uses MongoDB's Object ID layout (seconds since the epoch, a machine identifier, the process id and a counter) in 12 bytes, written as a 20-character base32hex string that stays URL-safe and sorts by time. That makes it shorter than a UUID's 36 characters and, unlike Twitter's Snowflake, it needs no machine or data-centre setup, while its binary form stays compatible with MongoDB Object IDs.
Problems it solves
- generate short unique IDs in my Go service without a central ID server
- IDs that sort by creation time and are shorter than UUIDs in URLs
- unique IDs across many servers without configuring each machine like Snowflake needs
Features
- 12-byte IDs as 20-character base32hex strings
- sortable by creation time
- no configuration or central server
- binary form compatible with MongoDB Object IDs
Alternatives
The same job
These do what xid does.
- gofrs/uuid A pure Go package for creating and parsing UUIDs
