Cosmos Application design question

BJ Kea 21 Reputation points
2022-12-30T16:05:04.53+00:00

I am designing and developing a web application with a Cosmos database backend.

One of my pages will have summary information and a data grid with detail rows.

Think shipping container information with a list of it's contents: ONE container has MANY boxes.

Current design has the summary information and detail rows in separate containers in the same Cosmos DB.

Is this poor design? Should I merge the documents and carry a collection of detail rows for each summary row? What are the pros and cons of having one document with a collection of details? Note the collection has a cap of 5 items. Similarly are there pros and cons to keeping the collections (summary and detail) separate and carrying two data sources on my Blazor page?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,374 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,438 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,837 questions
0 comments No comments
{count} votes

Accepted answer
  1. Mark Brown - MSFT 2,761 Reputation points Microsoft Employee
    2022-12-30T19:01:27.077+00:00

    Storing data like this in separate containers is an anti-pattern for a database like Cosmos DB.

    Your design objective here should be to reduce the number of calls made to read or write data. Data should be stored in the way it is used. Data that is always or frequently used together should always be stored together. Ideally within the same document or as separate documents within the same container.

    If you are new to using Cosmos DB I encourage you to look at the data modeling content I have put together in this gist, Cosmos DB Model and Partitioning Resources.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2022-12-30T16:50:12.273+00:00

    The trade offs in document databases is typically between placing all data in one document and the max documents size. If the document contains an unbound collection, or the elements of the collection are large, then they need to factored out and replaced with summary data.

    0 comments No comments

  2. BJ Kea 21 Reputation points
    2022-12-31T02:00:49.043+00:00

    Thank you Mark. I guess I was asking for patterns. On a plus side, combined, the total size of each the document is 5 summery properties and each detail document has 18 properties with a max of 5 items per collection. The original application, written in 2005, has accumulated data that will work out to be 50 total documents. Since I will be the only user of the application and I access it once or twice a month, I am hoping to use the free version of Cosmos.

    Thank you again!!!