Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I treat Couchbase bucket as table, or more like a schema

I am planing to use Couchbase as Documentation store in my web application. I am looking at Couchbase client for Java, and you need to create separate Couchbase Client for each bucket, if I treat Couchbase bucket as I would treat generic entity. This is a bit of overkill for the system (though, I can reuse executing service to minimize object creation and thread management overhead.)

So

  1. Is there a way to reuse existing CouchbaseClient for multiple buckets (Not only adding ExecutionService)
  2. Would not it be better to use single bucket, and distinguish objects based on the keys, and rely on views selectors for querying, from performance point of view.
like image 393
mavarazy Avatar asked Nov 11 '13 07:11

mavarazy


2 Answers

You should treat couchbase bucket like a database. One bucket per application in most cases should be enough. But I prefer to have 2 buckets. One for common data and one for "temporary" or "fast changing" (like cache, user sessions, etc.) data. For the last purpose you can even use just memcached bucket.

And answering your 2 questions:

  1. I don't know such way and never seen that someone even tried to do that. But remember that that client should implement singleton pattern. So if you have 2 buckets for your application, you'll only have 2 clients (that's definitely doesn't overkill something)

  2. As I said before treat bucket like a database. You even don't need to create test database. Couchbase has built-in separated dev and production views, and you can easily test your app on production data with dev views.

like image 143
m03geek Avatar answered Oct 05 '22 20:10

m03geek


About using a bucket as table/database, this post explains pretty well: http://blog.couchbase.com/10-things-developers-should-know-about-couchbase

  1. Start with everything in one bucket

A bucket is equivalent to a database. You store objects of different characteristics or attributes in the same bucket. So if you are moving from a RDBMS, you should store records from multiple tables in a single bucket.

Remember to create a “type” attribute that will help you differentiate the various objects stored in the bucket and create indexes on them. It is recommended to start with one bucket and grow to more buckets when necessary.

like image 30
G. Führ Avatar answered Oct 05 '22 20:10

G. Führ