Document Design: RaccoonBlog.Comments

81 views
Skip to first unread message

Tim Murphy

unread,
May 12, 2012, 10:14:20 AM5/12/12
to rav...@googlegroups.com
I'm reading RaccoonBlog source code to educate myself in the use of RavenDB.

How does the design and updating of https://github.com/ayende/RaccoonBlog/blob/master/RaccoonBlog.Web/Models/PostComments.cs not lead to loss of comments. If I understand this document and RavenDB correctly then this is what I think could happen if two comments are submitted at the same time:

Comment A loads PostComments for post 1.
Comment B loads PostComments for post 1.
Comment A and B have the same copy of PostComments.
Comment A is added to PostComments and saved.
Comment B is added to PostComments and saved. This save does not know about Comment A and therefore Comment A is effectively removed from the database.

Have I got this completely wrong? 

In such a situation does RavenDB throw an exception?

Why not save comments to a "standard" RavenDB collection? 

What benefit does PostComments give over saving comments to a standard RavenDB collection?

Itamar Syn-Hershko

unread,
May 12, 2012, 1:56:42 PM5/12/12
to rav...@googlegroups.com
It uses Optimistic Concurrency to make the comment is added to the latest version of the PostComments object, and fetches that doc again if it gets an indication of a change


It is done in the background so not to block the request

Oren Eini (Ayende Rahien)

unread,
May 13, 2012, 6:29:55 AM5/13/12
to rav...@googlegroups.com
Tim,
We use optimistic concurrency and reties to avoid this issue.
And putting this in a dedicated document means that loading the post page is just loading two documents by their ids, which is very cheap.

Tim Murphy

unread,
May 14, 2012, 5:54:00 AM5/14/12
to rav...@googlegroups.com
Oren & Itamar,

Thanks the explanation. I now understand whats happening.

Tim
Reply all
Reply to author
Forward
0 new messages