When should a new container be created in CosmosDB?

Viewed 401

I would like to store data of different structures on Azure CosmosDB. I know that a container can store different types of data. In production they're being differentiated by assigning them different "type" property.

As I was watching the best practices video: I noticed that there are two containers presented (timestamp: 17:47): Two containers in CosmosDB

The first one, users, has only one data types, while the second one, posts, includes two types of content: posts and comments.

  1. When would it be advisable to create a new container instead of adding data of different type to the one already created?
  2. Paraphrasing the question a bit: since a container can store various data types, why not put users, posts and comments from the screen above in just one container?
1 Answers

Data can be stored in the same container when it shares the same partition key and is accessed together.

You can't put users, posts and comments in the same container because users is partitioned on id, (essentially the user id) and posts is partitioned on postId.

Related