views:

250

answers:

2

I am contemplating the design of an event logging system based on couchDB.

What would be a good way of storing each event?

  1. one document with events as 'attachments'
  2. one document per event
  3. one document per event-type, events as attachments

Other?

+1  A: 

I would set one document for event. If it is event logging system, event is main entity, right? So IMHO it should be document, not just some attachment. This solution gives you flexibility when searching/filtering events.

amorfis
+1  A: 

I would definitely go for one document per event too. In addition to amorfis's answer, using attachments is likely to lead to contention over the document during updates unless you serialise updates very carefully. Just throw events into couchdb as documents as they happen and use views to slice and dice the events for analysis.

Matt Goodall
hmmm... contention in couchDB? I thought it was based on a "revision" system without locking. Explanation please?
jldupont
You can only update a document (including adding an attachment) if you have the current rev. A new rev is assigned each time a document is stored. So, if there are lots of things trying to update a document, e.g. a number of loggers, then they can end up "fighting" over the document. Losers much reload the document and try again.
Matt Goodall