Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js + CouchDB vs CouchDB

I'm questioning myself why should I use combination of Node.js + CouchDB versus CouchDB standalone approach. What are the benefits of getting Node.js into the game? Any comments/experiences are welcome.

like image 778
Gjorgji Tashkovski Avatar asked Dec 08 '11 22:12

Gjorgji Tashkovski


2 Answers

There is a third option: CouchDB in front, with Node.js in back...

Traditionally, a database is on the back-end, not the front-end, so this configuration seems sort-of "backwards", but hear me out...

In this configuration, you still serve all of your pages from CouchDB ( instead of Node ), and you use Node as a sort-of "worker process" that polls the DB for "jobs", processes them, and inserts the "results" back into the DB. This way you can use the full power of Node to do special processing, but you keep all the benefits of serving your app from the CouchDB.

Actually, in this configuration, you could have any kind of specialized workers that run Python or Java or Ruby or whatever. For example, suppose you have a "Create-PDF" function on your website, and you want to use Python to actually create the PDFs. You simply write a python program that watches the CouchDB for any "PDF_Request" documents, processes them, and inserts the PDF files back into CouchDB. You do not have write your whole app in Python, you can just write your PDF Create function in Python, and leave the rest of your app unchanged.

Now, suppose you replicate your CouchApp to another computer or a mobile device ( which runs CouchDB but not Node or Python ) No problem, you can still insert a "PDF_Request" into your CouchDB. When you eventually sync-up with the server, your PDF Request will then be seen and processed by the pdf creator program, and you will get your PDF File. Your couchapp still runs on the replicated CouchDB even though the "helper programs" are not there, because they are completely de-coupled from the main app.

I am not saying that this is "the way to go", just that because of the nature of CouchDB, this configuration is actually a viable option, and will give you benefits of scaling and replication that you would not get if you put Node in front and CouchDB in back.

like image 111
Nick Perkins Avatar answered Oct 17 '22 02:10

Nick Perkins


What Node can do and CouchDB cannot

Node.js can do inter-process communication using unix sockets, real time file uploads, it can start a websocket server or even a SPDY server.
You can create a DNS server or even handle some geo targeting stuff (MaxMind db).

Nice stuff CouchDB can do

However there are a lot of interesting things you can do with CouchDB, even if they would be a little more difficult to achieve. For example using the _changes feature you could do inter-process communication, a real-time chat system (long-polling).

I'm no expert (but CouchDB is top priority on my to-learn list), but I guess you could also simulate sessions for logged in users.

CouchDB is amazing and so is Node.js, so the important thing is what application are you planning to develop, what's your use case.

like image 36
alessioalex Avatar answered Oct 17 '22 02:10

alessioalex