Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thinking of storing serialized java objects into cassandra as JSON. What is the catch?

I am using Cassandra 1.2.2. I am finding it so easy to use Jackson to map my objects to and fro json and java for storing in database. I am actually tempted to do this to all of my data. My question is, Is this a good idea? What are the disadvantages of doing this to my application. My first guess is probably more processing overheads but is the juice worth the squeeze? and are there any other disadvantages that i need to know about?

like image 210
qualebs Avatar asked Mar 19 '13 13:03

qualebs


1 Answers

One disadvantage is that to modify the data you have to read in the original, deserialize, make your change, serialize and write out the whole object. In Cassandra, writes are much more efficient than reads so it is beneficial to avoid reads before writes if possible.

The alternative is to use separate columns for each field in your JSON. You can use composite columns for multi-dimensional data.

So if you had the data:

{
  name: "fred"
  address: "some town"
  age: 42
}

and you wanted to change the address, if you had these as separate Cassandra columns you'd just insert a column called address. If you had the JSON serialized you'd have to do much more work. This doesn't apply if your data is write-once.

Even if your data is write-once, if you just wanted to read one field from the data you can just read that column if stored separately rather than reading the whole thing and deserializing. This only applies if you want to read parts of your data.

In conclusion, there could be significant performance advantages to using separate columns if you have to update your data or if you only want to read parts at once.

like image 130
Richard Avatar answered Sep 19 '22 11:09

Richard