We are planning to SQL DB migration to Cosmos DB, as I am new in cosmos I am confused about container. Do we need to take one container for each table or one container is sufficient for all table data ? Suppose we are taking multiple container can we communicate different containers through Store Procedure?
1 Answer
To be successful here you need to understand how to model data and select a partition key in Cosmos DB. The concepts are very new and different than in a relational database. I would encourage you to read up on the differences as this has a huge impact on performance and cost in this type of database. This content will provide you with a solid understanding of how to design an efficient database that will scale:
(Note: have updated this answer to include more/better content given this answer is gaining traction)
Articles:
- Understanding the differences between NoSQL and relational databases
- Data modeling in Azure Cosmos DB
- How to model and partition data on Azure Cosmos DB using a real-world example
Videos:
- Modeling and Partitioning - 2 min intro
- How to model and partition data in Cosmos DB - This takes adventure works and remodels it for NoSQL
- Data Modeling in Azure Cosmos DB - This talks about modeling a book store scenario
Microsoft Learn Labs: (Essentially are HOL's for the second video above)
GitHub Repo:
- Cosmic Works - this is the code and data set for the adventure works talk above
Modeling in Cosmos DB requires you understand your data access patterns, how do I write data, read it and how often for each.
After you have an initial design you will need to test it and measure RU/s consumption to ensure you are fairly well optimized. It doesn't need to be perfect but you should know the answer to whether any cross-partition queries are better served by using ChangeFeed and writing data into another container with a separate partition key.
There are lots of concepts to understand. I know it's a common refrain but I definitely encourage you to read the docs on Cosmos before getting in too deep.