Comparing NoSQL: Couchbase & MongoDB
Fabian Piau | Friday March 8th, 2013 - 06:30 PMThe NoSQL world is vast: Cassandra, MongoDB, CouchDB, Redis, HBase, Couchbase, Neo4j, BigTable and so on. Not to mention Map-reduce, Hadoop, Hive that are quite close to NoSQL concepts… All these tools have recently been released to process very large amounts of data, what is called “Big data”. Take the example of Facebook, LinkedIn or Instagram with their millions of users and you will understand why relational databases have reached their limits.
The first relational databases were released in 1979 by Oracle, it’s been over 30 years they are used and they still may be used for a long time. While the first NoSQL databases have emerged 7 years ago, if we take into account Google as the NoSQL pioneer with its BigTable technology in 2006.
For us, developers, it has become difficult to navigate in this jungle of technologies. It would need plenty of free time and energy to test all of this. Moreover, the projects we are working on are often not facing the same issues (a few hundred users at most). In this case, a classic relational database such as MySQL will do the job!
This article is not an introduction to NoSQL, I suggest you read this article or this very complete document. They were written between 2010 and 2011. They are a bit old, but they are still accurate to understand the basics.
I will focus on these two NoSQL document-oriented databases. “document-oriented” or “document store” means that a key (identifier) matches a unique “document”. Don’t think about a complex document, but a simple JSON formatted text.
Here is a sample document:
{ '_id' : '5897g42s0245afo4o473ai1e7', 'firstname': 'John', 'lastname': 'Doe', 'age': 26, 'sex': 'M', 'interests': [ 'Reading', 'Running', 'Hacking' ] }
Couchbase and MongoDB databases are widely used today. They compete in a market, you will understand, quite saturated. Having used MongoDB (thanks to the 10gen training) and being aware to Couchbase (BruJUG session), I will make a comparison (probably not very objective) of the two systems. Things are changing so fast that I guess this article may be outdated in a few months…
A little history to begin with; MongoDB was created in 2009 by the 10gen company, Couchbase was created later in 2011 by the company of the same name.
Today, both systems are sharing many characteristics (open source, free, compatible with most platforms, good documentation…), but they differentiate on some points.
Scalability
In Couchbase, you can easily add servers to do clustering and obtain a distributed system, Couchbase is flexible enough to avoid downtime. Indeed, it relies on the power of the Erlang language, a functional and fault-tolerant language that manages hot changes.
For MongoDB, the configuration is a bit more complicated. For example, once you have defined the shard key (the key to distribute documents within a sharded cluster), it becomes difficult to change it afterwards. The system is not as flexible, so you have to think carefully about your data modeling before you move your application into production.
Scalability is why Couchbase is widely used in social gaming, where millions of players can play and their numbers can increase exponentially overnight.
Monitoring tool
Couchbase comes with a turnkey package while MongoDB requires an additional subscription to a monitoring service. You can monitor MongoDB using the command line, but a monitoring tool without graphical interface is relatively restrictive.
In the end, graphical products seem pretty similar, but the fact that you must register for MongoDB (even if it is free) and that the service cannot be self-hosted… Meh!
Querying data
MongoDB includes a variety of tools to perform queries. There is an equivalent for most of SQL operators, of course making joins is not possible. Someone coming from the SQL world will not be too disoriented and will find some similar concepts such as indexes and secondary indexes. You will find all operators available on this page.
With Couchbase, there are views like in relational SQL. It is a kind of a pre-written query in JavaScript, which is based on the Map-reduce concept. And that’s all! If you want to do more complex operations like filtering or aggregating your data, you must use Elastic Search (there is a Couchbase plugin available). Couchbase has chosen to focus on its NoSQL engine, letting the querying side to specialized search tools.
Conclusion
These two databases are commonly used and are supported by large communities. You will understand there is no winner or loser. As always, adopting a technology instead of another will depend on your needs.
Recent Comments