Bigflake

Build Status

128-bit, k-ordered, conflict-free IDs in Elixir.

This implementation draws heavily on Matt Heath’s Kāla project, as well as the Boudary’s flake.

The IDs it generates consist of:

Installation

This package can be installed by:

  1. Adding bigflake to your list of dependencies in mix.exs:

    def deps do

     [{:bigflake, "~> 0.0.1"}]

    end

  2. Ensuring bigflake is started before your application:

    def application do

     [applications: [:bigflake]]

    end

Usage

# generate an id
iex(1)> Bigflake.mint()
{:ok, 26868369774934248202951567081472}

You can configure Bigflake to use an integer or a 48-bit MAC address as a worker id. By default it will use the MAC address of the first device it finds.

# config/config.exs
config :bigflake, worker_id: :en1

Using with Ecto

# user.ex
defmodule User do
  use Ecto.Schema

  @primary_key {:id, Bigflake.Ecto.UUID, autogenerate: true}

  schema "users" do
    field :name, :string
    field :email, :string

    timestamps
  end
end

Benchmarks

(Results from a MBP i7 2.5Ghz)

mint ids     1000000   2.78 µs/op

LICENSE

See LICENSE