My first Erlang Project: Leveled a pure Erlang Key-Value Store

Martin Sumner
Builder and Operator of High-Availability Systems

Leveled is a pure Erlang Key-Value store, designed specifically as a new backend for Riak KV. Originally started as a personal project, it’s now ready to be used in the real world.

All backends for Riak KV have limitations: Bitcask has only partial feature support (in particular not supporting secondary indexes, which may also mean it can never support certain CRDT optimisations), leveldb requires a context switch form Erlang to C++ and suffers from side effects from write amplification if you have non-trivial value sizes.

Leveled is a Key-Value store designed to have full-feature support for Riak. Also, it comes with some specific optimizations, which when aligned with changes in Riak, can lead to both functional and throughput benefits. Testing in a variety of EC2 configurations with mid-size object contents (>4KB), has shown that there’s a 20% to 120% throughput advantage in having Riak combined with leveled in comparison to Riak combined with leveldb. You can find more information in the project’s GitHub docs:

In this talk I will show how we can take a problem (writing data stores) normally thought to require C/C++ magic to create a performant system, and deliver improvements instead in a pure Erlang based system.
The background to working on Riak comes from my work on the Spine II project at NHS. Taking a project like this in house, with its demands on both scale and availability, using this type of technology, has no parallels in the UK public sector.
At the NHS we’re really happy with Riak, but we’re continuously seeking to improve operational stability and efficiency, as well as advance our understanding of the detail of how our system works. Riak is the single most important part of our technology stack, so writing an alternative backend for Riak became a mission of mine: to learn more about Riak; to force myself to become more proficient in Erlang; and to see if alternative design trade-offs could make a system that was more efficient in the NHS use case.

In this talk you’ll find:

  • some history of the Spine project and the move towards Erlang on what is UK critical national infrastructure
  • a little about LSM-trees, and the design trade-offs in writing a tree, and how this relates to the Riak database
  • a little bit about how Erlang and message passing made a store relatively easy to write
  • some of the false steps in the process, in particular where I wrongly assumed that I would need NIFs for performance
  • a bit about my own experience tackling this project as someone new to Erlang, what I found hard, what I found easy

Previously a networks and operations engineer, Martin has spent the last ten years working on the design, build and running of highly-available applications. His most recent projects are the Spine II Core system at the NHS (the central database and messaging system for the Health Service in England), and an open source Erlang Key-Value Store called Leveled.

GitHub: martinsumner

Twitter: @masleeds

Back to conference page