Skip to content

Repository files navigation

Snowflake GUID

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)

Get started

This service is mostly used as a polyglot service within microservices. So gRPC protocol is best for it. No REST API support.

Run Development Server

go run cmd/main.go run

Build and Run

make binary
dist/snowflake run

Docker

Docker image project installation directory is /opt/snowflake. The default configuration file is /opt/snowflake/snowflake.toml.

gRPC

Generate gRPC code

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.

See also

There are sequence id generation implementations, but without time component.

License

The MIT License (MIT)

See LICENSE for details.

About

Distributed GUID service

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages