snowflake

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2022 License: MIT

README

= Snowflake GUID

Globally Unique Identifier(GUID) service inspired by https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake[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 (2^16^) than Twitter's (2^10^)
* It can generate 2^8^ 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`.


== License

The MIT License (MIT)

See https://github.com/prettykingking/snowflake/blob/master/LICENSE[LICENSE] for details.

Directories

Path Synopsis
genproto
pkg
cmd
log
rpc
snowflake
Package snowflake implements Snowflake, a distributed unique ID generator inspired by Twitter's Snowflake.
Package snowflake implements Snowflake, a distributed unique ID generator inspired by Twitter's Snowflake.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL