NoSQL – Document Database vs Relational Database: How to Choose?

nosqlrelational-database

I'm a SQL guy, but I know there is Not Only SQL databases – document-database mostly. As with most technologies there are pro and cons for each technology.

I've read some articles, but they were too theorical. What I would like is two real cases :

  1. when a switch from relational- to document-database gave an improvement
  2. when a switch from document- to relational-database gave an improvement

Improvement being any thing that makes better programs – less developpement time, scalabilty, performance, anything that is programming related.
There is a caveat for 2. : stories like " falling back to relational database because everybody knows SQL" is not good

Best Answer

The main reason for choosing a NoSQL database the last years have been Availability. For companies like Amazon, Google and Facebook an hour of downtime or so isn't acceptable. To achieve high availability you need to reduce single-point-of-failure, that means you need to use a distributed system with multiple computers in case a computer crashes, the service is still available.

Traditional Relatione databases isn't very good in a distributed multi-master setup. That's why NoSQL has been so popular lately. So if you need high availability you may choose a NoSQL database like Riak, Cassandra, HBase, S3 or BigTable.

There is a good blog post about Amazon's Dynamo that is a good introduction to distributed NoSQL databases.

Now, the NoSQL term is very broad so there are many NoSQL databases that aren't distributed. But they solve other problems. E.g. Neo4j - a graph database are good on a type of queries that traditional RDBMS aren't optimized for. Or as in your case a document database, where you don't have to change the schema if you want to add some fields for some documents. In other words a document database is good when most posts (documents) has different fields so a relational table with predefined columns isn't usable.

However, most of the NoSQL databases are not as flexible as traditional RDBMS databases are, so it's a good choice to use a traditional RDBMS database until it can't solve your problems anymore.

Related Topic