Globally Unique Identifier(GUID) service inspired by Twitter’s Snowflake algorithm, But it has different bit assignment from it.
A Snowflake GUID is composed of
39 bits for time in units of 10 msec 8 bits for a sequence number 16 bits for a machine id
As a result, Snowflake GUID has the following advantages and disadvantages compared with Twitter’s Snowflake:
-
The lifetime (174 years) is longer than that of Twitter’s (69 years)
-
It can work in more distributed machines (216) than Twitter’s (210)
-
It can generate 28 IDs per 10 msec at most in a single machine/thread (slower than Twitter’s)
This service is mostly used as a polyglot service within microservices. So gRPC protocol is best for it. No REST API support.
protoc --proto_path=./protos/apis \ --go_out=./genproto/apis \ --go_opt=paths=source_relative \ --go-grpc_out=./genproto/apis \ --go-grpc_opt=paths=source_relative \ protos/apis/snowflake/v1/resources/* \ protos/apis/snowflake/v1/services/*
For demo usage of client, see pkg/snowflake/snowflake_test.go
.
There are sequence id generation implementations, but without time component.
-
UID Generator - From Baidu
-
Leaf - From Meituan
-
TinyID - From DiDi
The MIT License (MIT)
See LICENSE for details.