7

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.
mavarazy
  • 7,562
  • 1
  • 34
  • 60

2 Answers2

10

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.

Imran
  • 87,203
  • 23
  • 98
  • 131
m03geek
  • 2,508
  • 1
  • 21
  • 41
  • Is there a performance drawback on views, since they'll need to process all the data, regardless of it's relevance? – mavarazy Nov 11 '13 at 13:44
  • 1
    Views process all data in background. So they don't "select" data when your query arrives, the data is already selected and server only do reduce (if it nessesary) on predefined data set and sends it to client, unless you send special param to your view, that will force it to update index before sending it to client. I.e. if your map function will have some `if` statements like `if {doc.type === 'sometype'}`, your view will operate with only `precalculated` set of documents with specified type. – m03geek Nov 11 '13 at 13:54
  • Here is a link to couchbase doc about views http://docs.couchbase.com/couchbase-manual-2.2/#view-basics . It can be slow only when you create new view on existing large database. All updates (adding new docs, removing docs) should be fast. – m03geek Nov 11 '13 at 14:08
4

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.

Community
  • 1
  • 1
G. Führ
  • 401
  • 3
  • 8