This is a simple implementation of the most famous unique ID generation algorithm Twitter snowflake
+--------------------------------------------------------------------------+
| 1 Bit Unused | 41 Bit Timestamp | 10 Bit NodeID | 12 Bit Sequence ID |
+--------------------------------------------------------------------------+
host, err := snowflake.NewHost(/* Your host's node id */)
// Error handling ...
id := host.Generate()
You can see an example by the following steps.
go build
./onlyID
Access via a browser like Google Chrome
http://localhost/GenID
- the first line is the generated id
- the second line includes Timestamp, NodeID, SequenceID, respectively.
- You should implement this algorithm inside your server. (for example: an ID generation server)
- Check out the
docker
folder, use Docker to build a image for your IDGenServer. - Deploy a distributed system with the image you have built.