I tried CouchDB and I like it



My COVID lockdown project is a system to keep a database updated called SUDSJS. I am using it to check out different database management systems (DBMS).  The latest is CouchDB - and I like it.

The software (a test system using MongoDB herehas a database driver and so I can try out different database management systems quite easily. I wrote a driver first for SQL systems, which I have tested with: MySQL, SQLite 3 and PostgreSQL. Then I wrote drivers for NOSQL systems: MongoDB, Firestore (sort of) and CouchDB.  

I am testing out the CouchDB version now and I like it. A lot.

The NOSQL market leader - MongoDB has a rich set of capabilities and is quite complex. CouchDB is also capable but (relatively) minimalist. It does this by being really, really cleverly designed. 

Tables/files/collections
CouchDB doesn't bother with old-fashioned ideas like collections (aka tables, aka files). All the data is in one big space.  It takes some getting used to, and sounds like a big problem, but once you get used to the idea, it is easy to work with

Views
To help you structure the date you have 'views'. These are really clever super-indexes. These revolve around a small JavaScript routine you write to specify what documents you are selecting, which field (or fields) is ordering the view and which other fields you are going to store in the view.  

For example, you have invoice documents. You might create a view that:
  • selects all document of type 'invoice 
  • sorts by invoice number within customer number 
  • also includes the deliver address and value.  
Now when you list off that view, your app gets the customer number, invoice number, delivery address and value. You don't have to go to the invoice document to retrieve these details.  Because it comes from the view that is sorted already, expect this to be lightning fast.  You might have to go to the customer view to get the customer's name though.

Normalizing the denormalized
You can create more than one view entry for each document. In the invoice example, you might have all the invoice lines listed in the invoice document. If you want an analysis of sales by product, you can create a view that has one entry for each invoice line.  

MongoDB has something similar called 'aggregation'.  But aggregation takes place when the query is made. Views are updated when the data is updated. So, queries will be much faster. 

Joins
If you are a SQL developer, you might look for Joins - they pull together all the related information around a particular record.  They are essential in a Normalized database, less so in document-based systems. MongoDB has Joins as a feature of its aggregation feature. CouchDB has a limited join function that, maybe needs work.  More on this with a future blog post.  

So, I like it.
I definitely do. If I were implementing a system with a monster database, I would spend a lot of time with benchmark results of different systems.  If I were operations manager, I would look for some sort of control panel. But if it were a normal to large system for which NOSQL works better, I would definitely look very closely at CouchDB.  I will be switching SUDSJS.com to CouchDB some time soon.




No comments:

Post a Comment