Recently I have been exploring the NoSQL options for .NET and specifically a database called Cassandra. In case you haven’t heard of Cassandra before, it is a decentralized, fault-tolerant, elastic database designed by Facebook for high availability. As Wikipedia describes it:
Cassandra is an open source distributed database management system. It is an Apache Software Foundation top-level project, as of February 17, 2010, designed to handle very large amounts of data spread out across many commodity servers while providing a highly available service with no single point of failure. It is a NoSQL solution that was initially developed by Facebook and powers their Inbox Search feature. Jeff Hammerbacher, who led the Facebook Data team at the time, has described Cassandra as a BigTable data model running on an Amazon Dynamo-like infrastructure.
I bet you have used data that has been served by Cassandra and not even realized it, here are some prominent users of Cassandra:
Sounds interesting or at least worth a look, right? Well I thought so, however during my journey of getting the database setup I have come to realize there is almost no documentation on installation for Linux, and even less for Windows. So I am going to provide you with a jump start to installing Cassandra on your machine. I am doing this so you don’t have to spend days jumping around the web, going down false paths, and pulling your hair out like I did, all so you can get on to what you really care about … development.
The first thing you need to understand about Cassandra is that it is developed in Java. So you can run it on any machine that supports Java 6 or better. So before you go any farther make sure you Java JRE is updated to the latest version.
The next thing you need is a copy of Cassandra. Which can be found here. My setup is going to be based off of the latest stable release.
As I said before you can run from an operating system that Java has a runtime for. So the first and probably most obvious one for a Windows developer, is running Cassandra on Windows. To install Cassandra on windows just follow these steps:
This is easy to get running, but there is some manual process that you have to go through each time to get the server running. In the future when you want to start up the Cassandra database for development, just repeat Step 4.
The other way, to run Cassandra is through a Virtual Machine running Linux. This setup is just as easy as the Windows setup as long as you have some experience with Linux. I am going to start the install steps assuming that you have already installed Ubuntu Server. This way the process is generic if you want to run the server on an physical or virtual machine.
Unlike Windows to startup this Cassandara database so that you can start using it for development, you just need to boot up the physical or virtual machine and it should be ready for development.
Thrift is a protocol also developed by Facebook to create agnostic interfaces for all the common languages based off a simple configuration file. The Thrift teamdescribes their mission as:
Thrift is a software project spanning a variety of programming languages and use cases. Our goal is to make reliable, performant communication and data serialization across languages as efficient and seamless as possible.
As I found out there wasn’t any good way to build the thrift executable in Windows, which is another reason the Linux VM came in handy. The thrift executable is needed to generate the protocol interface for Cassandra. You can read how to build the thrift executable here for your operating system.
After you have the executable you need to run it against the Cassandra interface definition. I am not going to go much into depth with this, because this part of the process is pretty well documented on the internet, but here is the command I ran to create the generated Cassandra interface for C#.
thrift -gen csharp cassandra.thrift
I am not going to leave you high and dry, I have already generated the Cassandra Thrift interfaces for the following languages for you:
Note: these where generated based on Cassandra 0.5.1, so that may and probably won’t work with future releases of Cassandra.
You can find the necessary supporting libraries for each of the above languages by going to http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/.
If you are like me and interested in using it with a .NET application here is a quick demonstration class that will help you get started.
But no matter the language you use, I hope this has provided you a good jump start with Cassandra.