JonathanBristow
JonathanBristow

Reputation: 1065

Couchbase - Large documents or lots of smaller ones?

I am building an application which allows users to post content. This content can then be commented on.

Assume the following:

  1. A document for the content is between 200KB and 3MB inside depending on the text content.
  2. Each comment is between 10KB and 100KB in size.
  3. There could be 1 comment, or 1000. There are no limits.

My question is, when storing the content, should the individual comments be stored inside the same document or should they be broken up?

Upvotes: 3

Views: 796

Answers (2)

a4xrbj1
a4xrbj1

Reputation: 425

I would go with a document for each answer as Couchbase is brilliant in organizing what to keep in memory and what not. Usually an application isn't displaying all comments when there is more than 25 (I think that's a number most applications use, display them in chunks of 25 with newer at the top eg). So if the latest 25 comments are kept in memory while older ones are subsequently automatically written to disk you keep an ideal level between how you use your memory (always critical with Couchbase) and access time for you application. Perfect balance I'd say, I had a similar decision to make in my application and it worked perfectly.

Upvotes: 3

mrkwse
mrkwse

Reputation: 420

I'd certainly keep the post content and the comments separate, assuming there will be parts of the application where the posts would be previewed/used without comments.

For the comments themselves (assuming they are separate) I'd say many smaller ones would typically be better, if only due to the consideration that there exists a post with 100s or 1000s of comments, you're not going to want to use them all immediately, so it makes sense to only get the documents as they are required (to be displayed), rather than loading MBs of comments to only use <100KB of what has been gotten at the time.

You might not require comments to be stored individually, but providing your keys are logical and follow a predictable scheme, I see no reason not to store them individually. If you would want some grouping, however, I'd probably avoid grouping more comments per document than would be typical for your usage.

If you are using views there perhaps may be some benefit to grouping more comments into single documents, but even then that would depend on your use case.

There would be no software bottlenecks from Couchbase for storing lots of documents individually, and the only constraints would be hardware constraints that would be very similar; whether you had lots of small documents or fewer large documents.

Upvotes: 5

Related Questions