Building an ORM for Riak

Author: Simon Cross
Date: 2 June 2012

Presenter Notes

What is Riak?

  • A key/value store (a GIANT hash table)
  • A product of Basho (
  • Apached licensed

Presenter Notes

Why Riak

  • Super easy to administer
  • Secondary indexes
  • Solr-like search interface
  • Map-reduce queries

Presenter Notes

Under the hood

  • The key space is a partitioned ring.
  • Vector clocks are used to determine ordering.
  • When conflicts arrise, keep both values.

Presenter Notes

Setting up Riak

Download package and install:

$ wget
$ sudo dpkg -i riak_1.1.2-1_i386.deb

Add another node:

$ riak-admin join riak@

Tweaks for /etc/riak/app.config:

{riak_kv, [
  %% Switch to backend that supports indexes
  {storage_backend, riak_kv_eleveldb_backend}

{riak_search, [
  %% To enable Search functionality
  {enabled, true}

Presenter Notes

Why an ORM

  • Description of data
  • Ease of use

Presenter Notes

What we want this to look like

class Contact(Model):
    """A contact"""

    user_account = ForeignKey(UserAccount)
    name = Unicode(max_length=255, null=True)
    surname = Unicode(max_length=255, null=True)
    email_address = Unicode(null=True)
    msisdn = Unicode(max_length=255)
    created_at = Timestamp(default=datetime.utcnow)
    groups = ManyToMany(ContactGroup)

Presenter Notes

How we wrote it

  • Descriptors
  • Database engine
  • Supports both sync and async in one code-base!

Presenter Notes