incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Wolff <>
Subject Tracking view updates with CouchDB
Date Thu, 16 Apr 2009 16:21:59 GMT
Hi list,
In our app, we are building a notification system. In the end, we need
a view sorted by a key and then update time. The update time is a
function of a number of different potential app operations --
including updates or commits of documents that refer to the id of the
doc that we are keying.

So we've got docs that look like this:
  type: "key_doc",
  _id : "xyzzy",
  key : "doc_key",
  updated : 1239896906303

and docs that look like this:
  type: "ref_doc",
  key_doc_id : "xyzzy",
  updated : 1239897055080

and we want a view that we query like this:
  startkey : ["doc_key",null], endkey : ["doc_key",{}]
which reduces to the key_doc ids that were updated since the startkey
date, in order, e.g.
  ["xyzzy"] in this case

One thing we could obviously do is to update they key_doc every time
we write a ref_doc, but we're concerned about contention for the
key_doc. We've settled on the idea of writing an extra doc every time
we write a ref_doc, which copies the key information from the key_doc,
like this:
  type: "notify_doc",
  key_doc_id : "xyzzy",
  updated : 1239897055080

Right now, we're POSTing this doc and relying on reduce to sort out
the most recent one.

One problem with this approach is that we get invalid keys in our view
output, because we are copying the keys from the key_doc into the
notify_doc. In our app, we end up needing to check that the key in the
key_doc still matches the key reported by our view.

I'm also a little worried about write/delete churn with this approach.

After writing this whole thing, I wonder if the notify business is a
premature optimization. We could try just putting the key_doc every
time; if the operation fails, *by defintion* there's a more recent

I'd love any thoughts from the list on this. Another option we have is
to punt and handle this all in our app -- the db just reduces a list
of key_docs by updated time and the app groups the docs by key.

Thanks in advance,

View raw message