Victus Spiritus

home

State Propagation with Multiple Databases

21 Sep 2010

Between a few stolen moments last night and early this morning, I was able to tweak the photo sharing app, Pics. One open issue, I may have borked Pics' upload interface this morning by commenting out a bit.ly url shrinking call.

The files I cared about most in the local couchapp were moo.html, Tyler's template for uploading files, and image.js, the specific JavaScript for creating the image array html. There's also a style sheet I'll need to track down if I want to customize the interface later.

I initially cloned the couchapp directory from a couchDB (please pardon any url errors, I'll update if needed when I get home):

couchapp clone http://(server)/(database)/_design (dir name)

After creating an empty database locally with Futon, I made changes and iteratively pushed them to my local couchDB:

couchapp push http://localhost:5984/(database)

The magic is in how state changes propagate

Late yesterday evening I continuously replicated a localhost couchDB to a remote one on couchone.com. Then I setup continuous replication back from the remote couch to my localhost. Two way continuous replication communicates state changes between either database's documents and design code (which is itself a document), providing synchronization. I haven't done tests to see how efficiently thousands or more remote nodes synchronize yet.

I extended the relationship to another couchone.com database so Michelle would have her own photo app site, and synchronized it with my remote couchDB. Changes to Michelle's couch propagated back to my couchone server, which propagated back to my localhost, all within a moment. Daisy chaining nodes worked flawlessly. I needed to manually refresh the browser, but I should be able to update part of the view if represented data changes, we'll see.

What's next

Besides mimicking features of peer to peer distributed file sharing systems (torrents), there are a few basic tasks I'll focus on this week. Loading directory trees of documents at once, as well as dumping multiple files to local disk would make use easier. I'd like to jazz up the interface to handle folders and/or organization tags and labels. Shared file repos could be browsed at a high level, likely as separate databases to enable independent synchronization. This enables sharing different media with my wife, my family, with Tyler, and and with my other friends. This form of segregated synchronization plays well with the different social groups I interact with.

Most production apps require some kind of authentication, so I'll add that as well. After that I'll investigate file support to enable sharing, showing (and editing?) additional media formats: video, music, PDF, doc, ePub, or anything that's easy to do in a browser.

Like it? Go ahead and "fork it" by cloning it to your own local or couchone.com CouchDB (installation help).