• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created over 13 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A clone of Twitter's Snowflake, built on riak_core

riak_id

Overview

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.

Design

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):

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

Caveats

  • 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.

Acknowledgments

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.

License

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

More Repositories

1

neotoma

Erlang library and packrat parser-generator for parsing expression grammars.
Erlang
300
star
2

eunit_formatters

Because eunit's output sucks. Let's make it better.
Erlang
70
star
3

yakriak

A Riak-powered Ajax-polling chatroom. Not for production use!
JavaScript
37
star
4

riak-url-shortener

A sample Riak + Ruby app, written with Sinatra and riak-client.
Ruby
37
star
5

hardhat

An opinionated, production-ready HTTP client for Elixir services
Elixir
32
star
6

datalog-elixir

Naively-evaluated Datalog, implemented in Elixir
Elixir
30
star
7

riak_zmq

Publish writes to Riak KV to 0MQ (based on linked gist)
Erlang
22
star
8

restful_workflow

A Rails plugin to implement interview-style workflows in a controller.
Ruby
21
star
9

nanocompiler

A nanopass-style compiler in Elixir, targeting BEAM, based on https://github.com/compilers-course-materials/
Elixir
15
star
10

paxos

Multi-Paxos for Erlang, based on "Paxos Made Moderately Complex" [PROTOTYPE]
Erlang
13
star
11

edn-erlang

edn for Erlang
Erlang
13
star
12

radiant-templates-extension

NO LONGER MAINTAINED. See http://github.com/avonderluft/radiant-templates-extension
Ruby
13
star
13

strangeloop-riak-mapred

Slides from Strange Loop 2011 - "Wrap Your SQL Head around Riak MapReduce"
JavaScript
12
star
14

survivors-game

A survivors/rogue-like game written in Rust using the Bevy engine
Rust
11
star
15

radiant-banner-rotator-extension

NO LONGER MAINTAINED. Use http://github.com/avonderluft/radiant-banner-rotator-extension
Ruby
11
star
16

radiant-feed-reader-extension

An extension for Radiant CMS that lets you display RSS/Atom/Feedburner feeds in a page, using Paul Dix's FeedZirra library.
Ruby
11
star
17

riak-sessions

Rails/Rack Session stores for Riak (formerly "ripple/riak-sessions")
Ruby
11
star
18

sedate

Story-Driven Acceptance Testing for Erlang (a Cucumber clone)
Erlang
10
star
19

twitterl

Erlang bindings for everybody's favorite webservice, Twitter.
Erlang
10
star
20

rqc

An implementation of QuickCheck in Ruby (NOT FUNCTIONING)
Ruby
8
star
21

swedish_chef

A re-implementation of the Chef server API in Erlang.
Erlang
8
star
22

webmachine-tutorial

WM Tutorial for LambdaJam
Erlang
7
star
23

rubyconf-webmachine

Slides from RubyConf 2011 - "Resources, For Real This Time"
Ruby
7
star
24

bbuzz-riak-mapred

Slides from Berlin Buzzwords 2011 - "Wrap Your SQL Head around Riak MapReduce"
JavaScript
6
star
25

weewar

Ruby bindings for the Weewar API
Ruby
6
star
26

radiant-atom-import-extension

Imports Atom feeds into a standard blog layout in Radiant.
Ruby
5
star
27

riak-cache

riak-cache is an ActiveSupport::Cache::Store that is backed by Riak. (previously part of "seancribbs/ripple")
Ruby
5
star
28

hanoidb-rs

An implementation of krestenkrab/hanoidb in Rust.
Rust
5
star
29

ex-tree-sitter

Experimental Elixir bindings (NIFs) to the tree-sitter library
Rust
5
star
30

pwl-chicago-1

Presentation sources given at the first Papers We Love Chicago
TeX
4
star
31

riak-qc.js

Test Riak map and reduce functions in Javascript, in a QuickCheck style
JavaScript
4
star
32

codehighlighter-languages

Extra or modified languages for Dan Webb's CodeHighlighter.js
JavaScript
4
star
33

beamruby

Basic Erlang NIF linking to mruby (EXPERIMENTAL)
C
3
star
34

riak-apps-jsconf2011

Presentation slides for JSConf 2011
Shell
3
star
35

ctf

Elixir
2
star
36

restfest-todos

RESTfest hackday app
Erlang
2
star
37

wm-stack

Batteries-Included Webmachine Project Template (WIP)
Shell
2
star
38

datalog-rust

An implementation of naively-evaluated Datalog, in Rust
Rust
2
star
39

prodigy

The seed of some remote automation for SmartOS
Ruby
1
star
40

hashtypes

Port of Elixir's HashDict and HashSet to plain Erlang.
Erlang
1
star
41

bdb

Implementations of BerkeleyDB based on https://transactional.blog/building-berkeleydb/
Rust
1
star
42

devise-ripple

An ORM strategy to use Devise with Riak
Ruby
1
star
43

crafting-interpreters

An implementation in Rust of the "Lox" language from Crafting Interpreters by Robert Nystrom
Rust
1
star