A clone of Twitter's Snowflake, built on riak_core
Erlang Shell Perl
Latest commit f4bb490 Nov 30, 2012 @vinoski vinoski in Makefile, expect rebar to be on the PATH
The Makefile was trying to call a rebar executable as a sibling file to
itself in the top-level project directory, but no such executable
exists. Since rebar is a de facto Erlang build tool nowadays, just pick it
up from the PATH instead.
Failed to load latest commit information.
LICENSE Add README and LICENSE. Apr 15, 2011
README.org Add a Webmachine resource so you can actually get those IDs. Apr 15, 2011




riak_id is a very simple application that serves both to duplicate functionality from Twitter’s “Snowflake” and to teach, via a very simple example, how to build a riak_core application.


The core functionality of riak_id is to provide k-sorted unique identifiers. The structure of the identifiers is very similar to Snowflake. They are 64-bit integers with the following layout (from highest to lowest):

1Signedness flag, always 0
41Unix timestamp, down to the millisecond
10Top 10 bits of partition number (see Caveats)
12Per-partition strictly increasing counter


  • Decent NTP synchronization between machines is needed for riak_id to work as expected.
  • Request failures (e.g. from partition, timeout) should simply be retried. You will eventually get an ID.
  • Because only 10 bits are reserved for the partition number, there is a practical ring-size limit of 1024. This should not be a problem because the work is mostly CPU-bound.
  • So that we can give reasonable guarantees of uniqueness, some requests may have a minimum latency of 1ms (to allow the timestamp to increment).
  • It will run out of ID space within the century. Snowflake solves this using the “Twepoch”. I didn’t bother with that, but it would be a simple feature to add.
  • I wrote riak_id to learn, I hope it will be useful to others.

Quick Start

riak_id requires Erlang/OTP, rebar and a sane GNU build system.

  1. Clone the repository, copy the rebar script into the repository.
  2. Run make rel from the command line.
  3. rel/riak_id/bin/riak_id console
  4. riak_id:next_id(). from the console to generate IDs.


Thanks to Jesse Newland, Andy Gross, Ryan Zezeski for their work on the rebar template for riak_core apps, without which I would be lost. Special thanks to Andy for pointing out some egregious errors in an early version of the vnode code.


Copyright 2011, Sean Cribbs. Licensed under Apache License 2.0.