Riak_Core with Elixir : Part One

Naveen Negi
Jan 5, 2017 · 2 min read

This is going to be a multi-part blog series in which I’ll show how can you build an riak_core application using elixir.

I won’t go into details of what riak_core is or what can be achieved using riak_core. You can read about it here.

In this part we will try to configure riak core in our application.


You would need to install erlang version 18 (please note that erlang version above 18 are not supported in riak_core as of now). Elixir version should be 1.3 or above.


We will create a mix project using command

mix new Vyuha --sup

once we have our project structure ready, we need to declare riak_core as a build time dependency in our mix.exs file.

defp deps do
{:riak_core, ">= 2.2.6", hex: :riak_core_ng}

Now we have to make sure that riak_core is started before our app by giving it as a runtime dependency. We will do it in application method in our mix file.

def application do
[ mod: {Vyuha.App, []},
applications: [:riak_core, :logger]]

In the first line, we specify the application module of our application (start/0 function will be called from Vyuha.App). In second line, we are telling mix to start riak_core and logger before it starts our application.


Before we start our application, we need to configure riak_core by setting some default values. We will do this in our config.exs file

config :riak_core,
ring_state_dir: 'ring_state_dir',
handoff_port: 8099,
handoff_ip: '',
schema_dirs: ['priv'],
ring_creation_size: 12,
vnode_inactivity_timeout: 1000

Here we are configuring riak_core for its different properties, like number of vnodes to create (which is 12 in this case), where to save ring configuration data etc.

Apart from configuring riak_core, we also need to configure two more runtime dependencies (these are part of elixir package). Again we will do this in config.exs

config :lager,
colored: true,
error_logger_hwm: 500
config :sasl,
errlog_type: :error

One more thing that we need to do before we can start our application is to create a “priv” folder under the root project folder and copy riak_core.schema from deps/riak_core. Run below command on root folder of your project.

> mkdir priv> cp -r deps/riak_core/priv priv

Building Project

Get dependencies by running following command.

mix deps.get

Now run the application by running following command

iex --name nav@ -S mix run

Here we have used a long name by providing a — name flag. This name identifies a Beam Instance on a machine. Name takes a form of arbitrary_prefix@host, where arbitrary_prefix is any name that you give to the Beam instance and host is the full ip address of the host machine. This will become important as soon as we try to run multiple Nodes on same machine.

This should start our riak_core application. In next post we will try to add functionality in our app. You can find code up to this point here.

Read part 2 here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store