Data Modeling and Partitioning Best Practice in Partitioned Repository Pattern With Cosmos DB

Discuss Data Modeling and Partitioning Best Practice for Cosmos DB and its implementation using Partitioned Repository Pattern with ASP.NET Core.

Shawn Shi
The Startup

--

UPDATE April 10, 2022: all projects in the GitHub repo have been upgraded to .NET 5.

Even though Cosmos DB is schema-free and supports storing and querying unstructured data, it is still critical to spend good efforts in the planning phase on data modeling and partitioning. Particularly, poorly designed data models and partition keys would hurt the performance and also restrict the scalability.

In this article, we will discuss:

  • how partitioning and logical partitions work in Cosmos DB
  • how data is stored in different logical partitions in Cosmos DB
  • how data is read from Cosmos DB, including Point Reads, Single-partition Query and Cross-partition Query
  • how to design partition keys for better performance
  • how partitioning can be implemented in Partitioned Repository Pattern using .NET SDK
Image by Author

How is data stored in different partitions in…

--

--

Shawn Shi
The Startup

Senior Software Engineer at Microsoft. Ex-Machine Learning Engineer. When I am not building applications, I am playing with my kids or outside rock climbing!