All Projects → maxcountryman → Flake

maxcountryman / Flake

Licence: bsd-3-clause
Decentralized, k-ordered unique IDs in Clojure

Programming Languages

clojure
4091 projects

Labels

Projects that are alternatives of or similar to Flake

Node Scalable Blob Store
A file system blob store that is designed to prevent conflicts when used with a distributed file system or storage area network
Stars: ✭ 31 (-76.52%)
Mutual labels:  uuid
Uuid Shortener
A simple RFC 4122 UUID shortener library. Change your long 36 chars long ID into it's shorter equivalent.
Stars: ✭ 81 (-38.64%)
Mutual labels:  uuid
Snowflake
java edition of [Twitter Snowflake](https://github.com/twitter/snowflake), a network service for generating unique ID numbers at high scale with some simple guarantees.
Stars: ✭ 114 (-13.64%)
Mutual labels:  uuid
Ksuid
Java implementation of K-Sortable Globally Unique IDs
Stars: ✭ 35 (-73.48%)
Mutual labels:  uuid
Hotelsystem
🏨TopView工作室一轮考核项目:一个酒店管理系统,提供查看房间,对房间进行模糊查询,预订房间,个人信息管理,房间和酒店信息管理(管理员)等功能,后台使用Java,tomcat,mysql,servlet,jsp实现,没有使用任何框架
Stars: ✭ 78 (-40.91%)
Mutual labels:  uuid
Uuid Random
Fastest UUID with cryptographic PRNG for JS
Stars: ✭ 87 (-34.09%)
Mutual labels:  uuid
Go Uuid
A wrapper for Linux kernel UUID v4 generator.
Stars: ✭ 26 (-80.3%)
Mutual labels:  uuid
Javascript
Universally Unique Lexicographically Sortable Identifier
Stars: ✭ 1,781 (+1249.24%)
Mutual labels:  uuid
Uuid Creator
A Java library for generating and handling RFC-4122 UUIDs.
Stars: ✭ 78 (-40.91%)
Mutual labels:  uuid
Fast Uuid
A Java library for quickly and efficiently parsing and writing UUIDs
Stars: ✭ 114 (-13.64%)
Mutual labels:  uuid
Ar Uuid
Override migration methods to support UUID columns without having to be explicit about it.
Stars: ✭ 41 (-68.94%)
Mutual labels:  uuid
Ble
✨Android BLE基础操作框架,基于回调,操作简单。包含扫描、多连接、广播包解析、服务读写及通知等功能。
Stars: ✭ 1,183 (+796.21%)
Mutual labels:  uuid
Fcuuid
iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor. 📱
Stars: ✭ 1,387 (+950.76%)
Mutual labels:  uuid
Instauuid
Instagram-Style Compact UUID generator library for Node.js
Stars: ✭ 31 (-76.52%)
Mutual labels:  uuid
User Bundle
A new Symfony user bundle
Stars: ✭ 116 (-12.12%)
Mutual labels:  uuid
Session Token
Secure, efficient, simple random session token generation
Stars: ✭ 12 (-90.91%)
Mutual labels:  uuid
Echo360
Commandline tool for automated downloads of echo360 videos hosted by university
Stars: ✭ 81 (-38.64%)
Mutual labels:  uuid
Electrode Csrf Jwt
Stateless Cross-Site Request Forgery (CSRF) protection with JWT
Stars: ✭ 127 (-3.79%)
Mutual labels:  uuid
Symfony Demo App
A Symfony demo application with basic user management
Stars: ✭ 122 (-7.58%)
Mutual labels:  uuid
Laravel Uuid
laravel uuid a simple, automatic UUID generator for any model based on Laravel
Stars: ✭ 103 (-21.97%)
Mutual labels:  uuid

Flake

Clojars Project Build Status Dependencies Status

Decentralized, k-ordered unique ID generator.

This is a Clojure implementation of Boundary's Erlang Flake ID service.

Usage

New flake IDs can be generated with the generate! fn from flake's core namespace.

Note that in order to prevent generation of duplicate IDs, init! must be called prior to generating IDs for the first time.

For example:

=> (require '[flake.core :as flake])
=> (flake/init!)
=> (map flake/flake->bigint (take 3 (repeatedly flake/generate!)))
(25978563106299135585558915252224N
 25978563106299135585558915252225N
 25978563106299135585558915252226N)

Here we have generated three BigIntegers which are flake IDs. Note how they are ordered.

It may be desirable to encode these IDs in a shorter representation, such as Base62. The utils namespace provides an encoder:

=> (require '[flake.utils :as utils])
=> (->> (repeatedly flake/generate!)
        first
        flake/flake->bigint
        utils/base62-encode)
"8mwFA958SJ2CZVu9nk"

A flake's middle-most bits are derived from a hardware address, e.g. MAC. If this is not desirable or the caller wishes to have more granular control over which bits are used here, a custom worker-id may be provided:

(import '[java.security SecureRandom])

(defn rand-bytes
  "Return `n` random bytes in an array."
  [n]
  (let [bs (byte-array n)]
    (.nextBytes (SecureRandom.) bs)
    bs))

(def worker-id (rand-bytes 6))

(first (repeatedly (partial flake/generate! worker-id)))

The above specifies a random array of bytes to be used as the worker-id.

Specification

Flakes are byte sequences composed of 128 bits. These sequences are structured such that the first 64 bits are a timestamp, i.e. the time since an epoch in milliseconds, the next 48 bits are a unique, machine-specific bitset, normally the MAC, and finally the remaining 16 bits are a monotonically increasing short.

A diagram of the flake byte structure:

[timestamp:64][MAC:48][sequence:16]

Exceptions

Exceptions may occur if a single machine generates more than 65,535 flakes within a millisecond. That puts the upper-bound on flake generation per machine at ~65 million flakes per second. If this limit is reached a IllegalArgumentException will be raised.

Additionally flake makes an effort to detect drift in system time and will raise IllegalStateException if time appears to be flowing in the wrong direction. Note that init! must be used for this to work properly!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].