Tuesday, March 9, 2010

JSON and NoSQL DB's



Last few months my work involved some web services stuff(SOAP). For a variety of reasons,SOAP was chosen over REST,which means i had to deal again with XML's.There are plenty of libraries and tools in market to parse or build a XML,but still never in my life i felt comfortable with xml parsers.
Heard a lot about json and wanted to give it a try some time.In my current work,there was a scenario,where i had to persist the state of object and reuse it at a later point of time.
yeah,immediate thing that came to my mind was xml.but then the complexity of using a binding framework like jaxb,castor,etc with their annotations,xml mapping file,blah,blah looked like complicating the whole stuff.my first try at json was like a breeze.

all i had to do was add a json library(i used google gson).the syntax looked like,
gson.toJson(object)
gson.fromJson(string)
That's it u just converted your string to json format and vice versa. As simple as it gets.more readable and it took only half the space to store the same data in the db.
so.. definitely JSON looks more simpler and efficient.recently ,many would have come across the buzzword "nosql" db.intial thoughts were,its not for enterprise applications. but the concept of non-relational database makes more sense now.

lets assume i had to save a simple registration form.the user inputs name,age and sex.a typical RDBMS in this scenario will have a table with 3 columns for name,age and sex and maybe one sequence generated ID column.sometime later,there is a new requirement to store address as well. yes,one ends up modifying the schema and face all the hassles related to data migration process.

what if we used a nosql db which stores data in key/value pair.lets say key is some unique id and value is the complete registration form.nosql db allows you to store the complete document as value to the given key.and they have seems to have a nice query language too.so,which means ur db is naturally scalable and its very much possible that you retrieve the data in json format and directly pass to the javascript in UI(in many scenarios).current javascript libraries like jquery,protoype,etc are getting better and better every day.

And there seems to be many big players in the nosql league like hbase,mongodb,couchdb,cassandra,etc. They are getting more attention as facebook,twitter,etc recently switched to such schema free database.Maybe its the end of RDBMS and XML world .