Cassandra : inverted index
Cassandra is the only NOSQL datastore Iâ€™m aware of, which is scalable, distributed, self replicating, eventually consistent, schema-less key-value store running on java which doesnâ€™t have a single point of failure. HBase could also match most of these requirements, but Cassandra is easier to manage due to its tiny footprint.
The one thing Cassandra doesnâ€™t do today is indexing columns.
Lets take a specific example to explain the problem. Lets say there are 100 rows in the datastore which have 5 columns each. If you want to find the row which says â€œService=app2â€, you will have to iterate one row at a time which is like full database scan. In a 100 row datastore if only one row had that particular column, it could take on an average about 50 rows before you find your data.
While Iâ€™m sure there is a good reason why this doesnâ€™t exist yet, the application inserting the data could build such an inverted index itself even today. Here is an example of how a table of inverted index would look like.
If you want to find the â€œstatusâ€ of all rows where â€œService=app2â€, all you have to do is find the list of keys by making a single call to this table. The second call would be to get all the columns values for that row. Even if you have 100 different rows in a table, finding that one particular row, matching your search query, could now be done in two calls.
Of course there is a penalty you have to pay. Every time you insert one row of data, you would also have to insert multiple rows to build the inverted index. You would also have to update the inverted index yourself if any of the column values are updated or deleted. Cassandra 0.5.0 which was recently released has been benchmarked to insert about 10000 rows per second on a 4 core server with 2GB of RAM. If you have an average of 5 columns per row, that is about 1.5k actual row inserts per second (that includes 5 rows of inserts/updates required for an inverted index). For more throughput you always have an option to add more servers.
Facebook and Digg are both extensively using Cassandra in their architectures. Here are some interesting reading materials on Cassandra if youâ€™d like to explore more.
- Digg: Looking to the future of Cassandra
- Facebook: Structured storage system on a P2P Network
- Jonathan Ellisâ€™ cassandra reading list
- An example of how â€œdelicousâ€ schema would look like in cassandra : asenchi
- Cassandra : Articles and presentations
- Getting started
- WTF is a supercolumn
- Cassandra internals