Sunday, September 8, 2013

Playtime: Riak, Azure, F#

Sifting through the programme for this years GOTO conference one of the talks I thought I'd go see was the one on Riak in the big data track. This is not a new topic at GOTO. In fact I've seen several really good Riaks talks there (like the Riak on mobiles one, that has also been at GOTO). Each time I've gone out of the talk thinking "I've gotta play around with Riak! It's cool." This time around I thought I'd start the playing around beforehand, with the added benefit that I have a bit more context coming into this years Riak talk.

What follows is a short account of my Hello World level experiences of getting Riak up and running on Azure and talking to it from a bit of F# sharp code.

Riak on Azure
As someone who works mostly on Windows the first thing I ran into with Riak is that there is no Windows option on the downloads page - it's different Unix flavors all the way through. Not worry though, in the cloud age spinning up a new Unix box is easy. As it turns out getting Riak on there is pretty easy too (just a few curl commands and that's it): I just followed the step-by-step guide to running Riak on Azure. The guide is little bit out of date with regards to the screenshots from Azure, but nothing that will trip you. The stumbling block was the very last curl command in the guide which is

curl -s | sh

but just gives you a redirect to a page on github. It's not a hard stumbling block though; you just follow the redirect and put in this command instead:

curl -s | sh

At this point I had a VM in Azure running Riak. I was able to put data into it and read it again through Riaks HTTP API simply using more curl commands.

Talking to Riak with F#
The basics of Riaks HTTP API are pretty easy - HTTP PUT to create a new key-value pair in a bucket, HTTP PUT to modify existing values, and HTTP GET to read them - but even doing that with curl gets a bit cumbersome pretty quickly. So here is how to talk to Riak with F# code using xUnit as an execution container.

First, checking the Riak cluster is even reachable can be done by pinging it like this:

Moving on to adding a key-value pair and implicitly creating a bucket too looks like this:

Finally reading data out again looks like this:

And that's it for getting data in and out of Riak from F# code.