Why I am moving to CouchDB

#sql-server#couchdb#mongodb

Why I am moving to CouchDB

Starting today, I will be using CouchDB as my primary database server for new projects and will gradually be moving existing projects to it.

I have been using Microsoft SQL Server for many years and never really gave it much thought - it just works - and I know how to make it work. And it is pretty fast given the right hardware and configured with the right indexes etc.

Late to the No-SQL party?

I know this sounds like swimming against the current - or being late to the No-SQL party. But this is really about the overall feature set of CouchDB specifically - and not an SQL vs No-SQL thing.

I don't have big data...

Many articles on why you might use No-SQL databases (like CouchDB) point to "big data" as the main reason. But I don't have "big data". My largest SQL database is around 5GB with a few million records total. So that's not it.

I don't need master-to-master replication...

As for CouchDB specifically, many articles point to master-to-master replication, filtered synchronization with client devices using PouchDB, or offline-first scenarios. Those are great features - but that's not it either.

So why CouchDB?

What about ad-hoc queries?

One advantage of SQL databases is that you can always write a quick SQL query to get out your data filtered, and sorted just the way you want - without regard to indexes (it may take a while but it will run).
With Photon (see above), you can actually do the same with CouchDB - query it using basic SQL statements.
CouchDB also has its own JSON-based query language called "Mango" (which is what Couch Photon SQL queries use behind the scenes).
You are NOT forced to create map/reduce views for all queries - like some internet posts would have you believe.

What about joins?

You won't need joins as much with CouchDB because of "de-normalization" (invoice-lines in same document as invoice itself).
But you can have linked documents which is a simple way of doing 1st level joins.

What about the horror stories of slow re-indexing when changing design documents?

I read them too. So I ran some tests.
I first created a CouchDB database with 500,000 documents (real-life data copied from a SQL database), then created a new design document / view, then did a query against it, then waited... for about 1 minute, and then it was all indexed and responding crazy fast. And this was with CouchDB running on my old laptop!
This does not scare me.

What about rumors that CouchDB is a disk hog?

I read them too. So I ran some tests.
Compared to SQL Server, it does use almost twice as much disk space for data (after compression / compacting). This is understandable given that "column names" are stored in every "row".
And it seems that you need to schedule compression on a regular basis to prevent data files from "exploding".
For me, this is an acceptable tradeoff.
One of the original selling points of SQL and "normalization" was preservation of disk space - because disks used to be slow and expensive. Neither is the case today.

What about MongoDB?

I did of course also look at MongoDB - the more popular choice amongst No-SQL databases and similar to CouchDB in concept.
From what I gather, MongoDB has better performance and tooling, but it is also more complex and not as lightweight (it uses much more memory).
MongoDB uses a proprietary client access protocol and thus needs proprietary client libraries/drivers (vs just using HTTP REST).
It uses BSON rather than JSON.
MongoDB is a 572MB download - CouchDB is 66MB.
From what I have seen, CouchDB is plenty fast, and I do prefer simple and lightweight over complex and heavy :-)

Conclusion

I have been "playing" with CouchDB on a few side projects, and the experience has just been fantastic so far.
I am now ready to go all-in :-)

Jesper Høy's
Dev Blog

  • Home (blog posts)
  • About me and this website
  • My developer tech stack
  • My favorite software
  • My favorite online services
  • Cool stuff
  • My side projects
  • Referral codes
  • Our wonderful ice horses