Code Monkey home page Code Monkey logo

snowflake's Introduction

snowflake

Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.

Goal

  • developing a c library package.
  • quickly use as a CLI application.
  • extension to lua.
  • extension to go.

Installation

There are three ways to use snowflake:

Library

In this way, you can use snowflake as a static library in your project.

mkdir build && cd build
cmake ..

make snowflake_lib

Then you can copy the build/libsnowflake.a to your project or install it to your system manually.

CLI application

In this way, you can use snowflake as a CLI application.

mkdir build && cd build
cmake ..

make snowflake_cli

Then you can copy the build/cmd/snowflake/snowflake to your system path.

Lua extension

In this way, you can use snowflake as a lua extension.

mkdir build && cd build
cmake ..

make snowflake_lua

Then you can copy the build/contrib/lua/snowflake.so to your lua package.cpath.

Generation process

Each time you generate an ID, it works, like this.

  • A timestamp with millisecond precision is stored using 41 bits of the ID.
  • Then the machineID is added in subsequent bits.
  • Then the counter is added, starting at 0 and incrementing for each ID generated in the same millisecond. If you generate enough IDs in the same millisecond that the sequence would roll over or overfill then the generate function will pause until the next millisecond.

References

snowflake's People

Contributors

yeqown avatar

Stargazers

 avatar  avatar

Forkers

hotion

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.