Giter Club home page Giter Club logo

moltenflake's Introduction

MoltenFlake

A distributed unique ID generator

Description

This is a distributed UID generator implemented in Java (using Spring) in the context of practicing system design. This is one of the systems that is often considered basic in system design and the most common and obvious approach is what is known as Twitter's Snowflake.

This implementation is satisfying the following requirements:

  • return unique numerical 64bit IDs
  • IDs are ordered by date
  • ability to generate over 1 million IDs per second

The generator is using a combination of the timestamp (milliseconds) the machine ID and an increasing sequence to generate a unique IDs.

It uses 41 bits for the timestamp, 11 bits for the machine and 11 bits for the sequence.

It has a planned capacity for 2048 hosts each generating up to 2048 ids per millisecond (2048000 ids per second) each. The capacity of the distributed system is 2048 * 2048000 = 4,121,440,000 UIDs per second.

As the timestamp advances 31536000 seconds per year we can adjust the number of bits allocated to the timestamp/machineid/sequence to accommodate for more load, more machines or longer lasting system.

For example, if we do not plan to be around for that long we can make a trade-off on the timestamp bits and increase the number of hosts or the max sequence number to increase the system capacity.

Using 40 bits for the timestamp the system will serve us for up to 17 years. Using 40 bits for the timestamp the system will serve us for up to 34 years. Using 41 bits for the timestamp the system will serve us for up to 69 years.

Requirements

The implementation is using Spring to provide a very simple HTTP api but other methods may be added (eg gRPC). The system requires a host whose time is accurate. The design also assumes that the system may also be load balanced and each instance has its own unique machine id. Setting the machine id is a responsibility of the process that maintains the intances.

Notes

The implementation was developed in a "clean room" style but due to its simplicity its similarities with Twitter's Snowflake are unavoidable.

Licence/Disclaimer

This implementation is released under GNU General Public License v3.0. Please keep in mind that this implementation is not production tested and comes with absolutely no guarantee that it will work for you.

moltenflake's People

Contributors

ntsakonas avatar

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.