CouchDB and data storage

Alexander Lang has written a great article about why CouchDB is not compatible with ActiveRecord, and why you should not try to coerce CouchDB into mimicking a relational database. It really is a very different thing altogether: The case of ActiveRecord vs. CouchDB

In my experience of CouchDB i first tried out ActiveCouch because of my familiarity with ActiveRecord. I soon came across problems because it was trying to make CouchDB something that it is not. As i exclaimed at the time, “LOL. ActiveRecord this is not!”

I had far more success with couchrest which is a much closer CouchDB wrapper, enabling CouchDB to be used as it’s intended: as a RESTful interface with map/reduce views.

Domain-Driven Design

Recently i have been reading Domain-Driven Design by Eric Evans. Through reading it my understanding of Rails – and web programming – has completely turned around. My thinking used to be entirely database-centric. I saw Rails as little more than an easy access into the database. For ages i didn’t even realise that you could have models that weren’t connected to a database table!

Now my thinking has changed and i consider the primary focus to be the domain model. I think about the classes and the design patterns that apply to them. I consider how they fit together, how they communicate with each other, and the boundaries between the core domain and subdomains. In my mind, the database has gone from being the most important thing to being just a method of persistence for the data in the domain model.

When you think of things this way round you are less likely to get hung up on the differences between ActiveRecord and CouchDB. You work out your domain, design the classes and then think about the most appropriate database platform to support your model.

Update: I’ve just come across a useful article that provides three methods to achieve a has_many relational structure in CouchDB. CouchDB “Joins” by Christopher Lenz.


24 comments on “CouchDB and data storage

  1. thanks for the hint. sounds like an interesting book. i think the rails-as-a-database-wrapper idiom is spread way too far. sounds like you managed to get away from that though :)i know the idea of being able to model your domain objects without having to worry about persistence and slap on the database afterwards sounds tempting. i would still argue that the database you choose has an impact on your domain models – depending on what your specific database is good at you still have to make sacrifices or do things a certain way – which you have to take into account.

  2. True, you have to take everything together as a whole. Much as we might focus on different layers of the architecture at a time, they come together to form an overall picture. Some projects are fine with Sqlite, some are suited to MySQL, and some would work well with CouchDB.Thanks for commenting, and i enjoyed reading your article.

  3. Pingback: Relational databases are dead « Dead Ink Vinyl

  4. Hi, interesting post. I have been thinking about this topic,so thanks for posting. I'll probably be coming back to your posts.

  5. I had far more success with couchrest which is a much closer CouchDB wrapper, enabling CouchDB to be used as it's intended: as a RESTful interface with map/reduce views.

    I've made the same experience.

  6. Indeed, as a reader to this blog I am truly impressed, have been coming across posts that are so very informative for me, keep impressing us!Dave

  7. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s