Best Practice for how to store Data
Hi,
this is more of a general newbie question to get an idea how to do what. I am writing an mobile App
which fits into the social spectrum. My app allows people to comment and like as well as tag other
users similar to the Facebook approach. Her is my questions..
a) What is the limit of how many documents couchbase can store in a bucket ?
b) am i save to assume bucket is the equal of a table in SQL, if not what is the benefit of
using buckets.
c) Lets assume i have million of objects which require a to store comments and like, what is a more efficient
approach storing each comment in its own document or go and store all documents related to one object in
a jason doc in one do ? to keep the doc count low i was thinking of storing all comments and likes for one
object in a single doc.
So it would be helpful if someone can share their experience with me and point me in the right direction
thanks
Hi makeawish
Buckets are similar to databases rather than tables. Depending on your hardware we would recommend some where from 2-4 buckets to 7-10 buckets.
If you take a look at the architecture, http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-introductio... you will see that for each bucket, an instance of the bucket engine (component) is created. Each bucket takes up a part of memory and it is managed independently. Using multiple buckets could lead to heavy CPU usage.
Typically, multiple objects are all stored in a single bucket. There is no limitation on the number of documents you can store in a bucket. On large clusters, users store millions / billions of documents.
Also given the power of Javascript map functions, secondary indexes can be created on attributes for each document type.
Example:
function(doc, meta) {
if (doc.jsonType == "player") {
emit(doc.experience, doc);
}
}
so here's some specific answers.
a) What is the limit of how many documents couchbase can store in a bucket ?
No limit, scale your cluster out by adding nodes and store more data.
b) am i save to assume bucket is the equal of a table in SQL, if not what is the benefit of
using buckets.
No, its more like a database, so store multiple objects together so that your application can cross reference objects easier.
c) Lets assume i have million of objects which require a to store comments and like, what is a more efficient
approach storing each comment in its own document or go and store all documents related to one object in
a jason doc in one do ? to keep the doc count low i was thinking of storing all comments and likes for one
object in a single doc.
Take a look at http://www.slideshare.net/ddborkar/navigating-the-transition-from-relati... Slide 15-20.
It depends on how many comments you expect per main document. Storing all comments in a single object makes it easier for development because you can directly reference one document and get all the related information. However, if the documents grow long, it is may be more efficient to split them out or group them as shown in the example.
hope this helps.
More examples and information on views can be found here:
- http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writi...
- http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-sampl...