I love CouchDB and node.js. I have found myself using them lately, to get a lot of things done, and would like to talk about why a person might want to use them or why they might be stupid tools for building your next app.
What's It All For?
The Solution Looking For Need
Node.js solves a lot of problems that I don't have. In general, I don't get blocked by IO operations, as most of the things I make don't need to scale ginormously. PHP can do a lot, pretty fast. PHP is an old, reliable workhorse for "getting things done" and is my fallback, for anything on the web, while I generally use Python for shell scripts. I know their quirks, and I can make nice things pretty fast with them. They've both got loads of libraries that make tedious things like building MIME emails, rendering PDFs, manipulating images, etc go really fast.
CouchDB also solves a lot of problems that I don't have. I am not trying to scale infinitely, a massive app that has billions of hits. I'm not finding PostgreSQL/MySQL to be a bottleneck, I am not in need of a lighter web-server+database full-stack. PostgreSQL, MySQL, Lighttpd, nginx, and even Apache serve me well, and I have never run into a situation that code-optimization + tools like memcached, Varnish, or nginx as a proxy/accelerator couldn't solve. CouchDB can render a lot of these tools unnecessary, as it is built with these things in mind, or obviates the need, from the start. It replicates very easily, and scales massively.
But wait, why learn a bunch of new things?
You may wonder, if I can solve all my problems with PHP/Python + a decent database + an ok webserver, and if needed, some caching: why oh why would I attempt to learn a whole new stack of unfamiliar technologies that I don't really need? I'll try to explain.
Enough about your feelings, what can I make?
You have these options (and I'm sure others that I haven't thought of) for how to set things up:
- node.js + couchdb on a webserver (web page)
- couchapp on remote server (web page)
- couchapp on desktop/mobile
- HTML5 client-side storage
- weirdo hybrid running awesomely client-side and server-side
I will explain each, in detail.
This is easiest (with your vast and awe-inspiring experience making webapps in RoR, PHP, etc,) if you want a web-only (possibly responsive-designed for mobile...) app. You get all the benefits mentioned above, including speed, asynch operations, fast data, data-replication + scaling, light web-service (node does it on it's own!)
Now, this is just cool. We start to get into some real magic voodoo type stuff, right here. You can host the whole app, in the database. It's versioned, and you can replicate the app files as well as the database. This is crazy! Slightly trickier to setup than #1, but Reapuhlster & couchbase can help make it a snap. Go make a crazy self-replicating AWS cluster couchapp version of facebook or twitter, and you will be rich! couchapps need creative solutions to secret data, that you don't want clients getting into using authentication and segmenting data on different databases (some replicated, some not.)
There are easy to use mobile and desktop versions of CouchDB. You can do the same as #2, but local. replicate to a master "app server", and you can roll-out updates, just by deploying your app. Neato! It should be noted that the mobile CouchDB stuff is super-new, and still has a few kinks to work out.
This is a great option of 1-page apps (or web-worker enabled apps.) You just use local storage. Works great for anything that doesn't need to call home or interact with other people on the internet (todo list, note-saver, etc.)
In later articles, I will give examples of each of these moments of development-cycle-encapsulated joy.