On Oct 28, 2008, at 10:17 AM, Chris Anderson wrote:

When a message comes from a phone, create a document like so:

{
"_id":"0b3a963dc37079652fa3092223be35b5",
"_rev":"1805961941",
"message" : "hey all this is the message",
"phone": "971 555-1212",
"time": "2008/06/30 06:30:35 +0000"
}

this document would never need to be updated, except in the case of deletion.

Also maintain docs for groups, eg:

{
"_id":"0b3a963dc37079652fa3092223be35b5",
"_rev":"1805961941",
"group" : "a group can have a title",
"phones": ["971 555-1212","818 555-1212", "503 555-1212", "512 555-1212"],
}

Then to load all the messages from phones in a group, GET the group
document, then run a multi-key request against a map view of the
messages, which is keyed by phone number. You have the whole thing in
2 requests.

the issue i see with that, and with any approach that requires a mutli document design with couch, is how to perform multi doc updates. take the above and imagine someone changes their phone number, getting all the messages and updating them, along with any group documents, is very error prone as it consumes a ton of read/write pairs during which any failure of the system could leave the db in an inconsistent state. this applies to the more mundane task of just making a tweak to the data too - like say we realized our code was appending 1+ for domestic numbers and shouldn't have been.... i guess the more general issue is that, with couch, keep denormalized data like this (the phone number) is problematic since there is not way to update it with acid properties.

having said that this does seem like a great application for couch.

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama



Reply via email to