A highly scalable and serverless unique ID generator for use in distributed systems. Written in GoLang. Inspired by Twitters Snowflake.

GOFLAKE

goflake

GitHub go.mod Go version Github code coverage GitHub repo size GitHub tag (latest by date) GitHub last commit GitHub

Go Report Card Go Docs Mentioned in Awesome Go

A highly scalable, customizable, and serverless unique ID generator for use in distributed systems. Written in GoLang. Inspired by Twitters Snowflake.


GoFlake is a small library that quickly generates unique identifiers in the microservices space that don't require an additional server to operate. It is based off of Twitters Snowflake project.

  • Its criteria are :
    • A check digit
    • An epoch time in Milliseconds
    • A service number
    • A process ID for the machine
    • A sequence number.


The Check digit uses 0 by default. The purpose for it is for auditing. You can set the checkdigit to a 1 later if you wish and observe all IDs that were generated with a 1. Use it as an event code if you would like. Its your call.

Running things on the same clock in distributed systems is a tough problem to solve. An Epoch time is used. The Epoch time is set in components/epoch.go . Set an epoch time in milliseconds that you would consider your microservice's Epoch and whenever an object is created the time since then in milliseconds will be generated into the IDs field.

A service number is used to determine where the object created is being used. For example 311 . In my Microservice 3 is for the Comments Service. 1 for the REST protocol. and 1 for the Deployment method - localhost. This can be tailored to your liking.

The process ID is the next field and is taken from the machine that is running the service

Finally a 5 digit random sequence number adds a 5 character string with : a-z A-Z 0-9

A generated Identifier would look like this : 0-14591498880493-0311-425471-43Que




Installation

Linux:

If you have GoLang installed. Clone the repository, CD into it and :

go run main.go 

This should run an example.

Copy the generator and components packages into your folder. Add them into mod.go to use GoFlake in your microservice. The packages also come with full code coverage.

Usage example

func main () {

	for i := 0; i <= 100; i++ {
		fmt.Println(generator.GenerateIdentifier())
        //will print 100 IDs 
	}

}

Set your options in the generator/generateid.go and then the GenerateIdentifier() function returns a unique identifier.

Additional documentation is available through godoc. http://localhost:6060/pkg and can be found under "Third Party". The Go Reference is available at https://pkg.go.dev/github.com/hart87/goflake

Release History

  • 1.0.0
    • Minimum Viable Product

Meta

James Hart – [email protected]

Distributed under the Apache license. See LICENSE for more information.

https://github.com/hart87/goflake

Contributing

  1. Please submit any pull requests on the master branch. If you add a feature, please submit it with a passing test.
Owner
J. Hart
Working on stuff in the cloud.
J. Hart
Similar Resources

📖 Elegant changelog generator

English | 中文简体 whatchanged An elegant changelog generator. Focus on Elegant/Simple/Efficient/Scalable Feel the magic online Feature: Cross-platform su

Nov 11, 2022

Log-generator - A simple CLI tool that generates near real logs for testing

Log-generator - A simple CLI tool that generates near real logs for testing

Jan 22, 2022

Go-generate-cv - Simple CV generator developed in Go

go-generate-cv Simple CV generator developed in Go Milestone Have a form to fill

Jan 10, 2022

Golog is a logger which support tracing and other custom behaviors out of the box. Blazing fast and simple to use.

GOLOG Golog is an opinionated Go logger with simple APIs and configurable behavior. Why another logger? Golog is designed to address mainly two issues

Oct 2, 2022

distributed monitoring system

distributed monitoring system

OWL OWL 是由国内领先的第三方数据智能服务商 TalkingData 开源的一款企业级分布式监控告警系统,目前由 Tech Operation Team 持续开发更新维护。 OWL 后台组件全部使用 Go 语言开发,Go 语言是 Google 开发的一种静态强类型、编译型、并发型,并具有垃圾回

Dec 24, 2022

CNCF Jaeger, a Distributed Tracing Platform

Jaeger - a Distributed Tracing System Jaeger, inspired by Dapper and OpenZipkin, is a distributed tracing platform created by Uber Technologies and do

Jan 3, 2023

A distributed logger micro-service built in go

Distributed Logger A distributed logger micro-service built in go using gRPC for internal communication with other micro-services and JSON for externa

Nov 6, 2021

Self-use log encapsulation for golang

package app import "github.com/restoflife/log" func Init() { log.Ne

Dec 29, 2021

A simple to use log system, minimalist but with features for debugging and differentiation of messages

A simple to use log system, minimalist but with features for debugging and differentiation of messages

A simple to use log system, minimalist but with features for debugging and differentiation of messages

Sep 26, 2022
Simple, configurable and scalable Structured Logging for Go.

log Log is a simple, highly configurable, Structured Logging library Why another logging library? There's allot of great stuff out there, but also tho

Sep 26, 2022
BTFS - The First Scalable Decentralized Storage System - A Foundational Platform for Decentralized Applications

go-btfs What is BTFS? BitTorrent File System (BTFS) is a protocol forked from IPFS that utilizes the TRON network and the BitTorrent Ecosystem for int

Jan 1, 2023
This POC is built with the goal to collect events/logs from the host systems such as Kubernetes, Docker, VMs, etc. A buffering layer is added to buffer events from the collector
This POC is built with the goal to collect events/logs from the host systems such as Kubernetes, Docker, VMs, etc. A buffering layer is added to buffer events from the collector

What is does This POC is build with the goal to collect events/logs from the host systems such as Kubernetes, docker, VMs etc. A buffering layer is ad

Nov 11, 2022
Metrics dashboards on terminal (a grafana inspired terminal version)

Grafterm Visualize metrics dashboards on the terminal, like a simplified and minimalist version of Grafana for terminal. Features Multiple widgets (gr

Jan 6, 2023
Distributed simple and robust release management and monitoring system.
Distributed simple and robust release management and monitoring system.

Agente Distributed simple and robust release management and monitoring system. **This project on going work. Road map Core system First worker agent M

Nov 17, 2022
Shikhandi: a tiny load generator for opentelemetry and heavily

shikhandi is a tiny load generator for opentelemetry and heavily inspired by thi

Oct 7, 2022
mango is a man-page generator for the Go flag, pflag, and cobra packages
mango is a man-page generator for the Go flag, pflag, and cobra packages

mango mango is a man-page generator for the Go flag, pflag, and cobra packages. It extracts commands, flags, and arguments from your program and enabl

Dec 23, 2022
Distributed, lock-free, self-hosted health checks and status pages
Distributed, lock-free, self-hosted health checks and status pages

Checkup is distributed, lock-free, self-hosted health checks and status pages, written in Go. It features an elegant, minimalistic CLI and an idiomati

Dec 30, 2022
Nightingale - A Distributed and High-Performance Monitoring System. Prometheus enterprise edition
Nightingale - A Distributed and High-Performance Monitoring System. Prometheus enterprise edition

Introduction ?? A Distributed and High-Performance Monitoring System. Prometheus

Jan 7, 2022
A feature-rich and easy to use logger for golang
A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang ?? Install ?? Common Logs lumber.Success() lumber.Info() lumber.Debug() lumber.Warning()

Dec 31, 2022