Buckets vs Tables vs Keyspace


I am confused about the new keyspace system introduced with N1QL. In the past, a bucket could be seen as a database (“put all stuff in one”) and now the docs say that a bucket / keyspace is more like a table.

What about the common bucket amount limitations (“you should not use more than 5 buckets per cluster”). If I treat a bucket like a table for my web app then I can easily end up with more than 10 buckets?!

Does it slow down a lot queries if I put all documents (products, users, comments) in a single bucket?

Hi Sebastian,

The total number of buckets is still limited, so you take that into account for your web app.

N1QL gives you the flexibility to index and query both within buckets and across buckets, and the buckets can be heterogeneous, with multiple doc types. For now, a keyspace is just a bucket.

You can put multiple types of documents in one bucket, and then index on type and other attributes. You can also create partial indexes, if you put a WHERE clause in the CREATE INDEX statement.

Your queries should then filter on type in addition to any other conditions. If your indexes and queries are designed this way, you should get good performance even with a single bucket. Use EXPLAIN to verify your queries.

Finally, if your app can fit within a few buckets (less than the limit), you are free to model your data that way as well. N1QL provides JOIN and NEST for querying across buckets. We wanted to give you the flexibility.


Thank you Gerald, that helped a lot!