Azure Cosmos Base Update Template

I recently started using Cosmos DB for a project, and I have a few design issues. Based on the SQL background, I understand that related data must be embedded in documents in a NoSQL database. This means that documents can become quite large.

Since partial updates are not supported, what is the best design pattern to implement when you want to update a single property in a document?

Do I have to read the entire side of the document server, updating the value and writing the document back to complete the update? This seems problematic if the documents are large, which would inevitably be if all your data is nested.

If I approach to make many smaller documents and establish relationships based on identifiers, I think that this will solve the problem of reading / writing, which should be immediate for updates, but it seems to me that I go against the concept of NoSQL, and essentially I am building a relational database.

thanks

+13
source share
4 answers

Lock and Lock. . What should happen if partial updates are possible. This is a complex engineering problem, which is to support SLA with a delay of 15 ms with a lock.

This seems problematic if the documents are large, which would inevitably be if all your data is nested.

Define your fear and mind; burnt request units, application host memory, incoming / outgoing network traffic? You think this is a problem, but you do not indicate specific results. I am not saying that you are mistaken or doubt the effectiveness of the partial update approach, I am simply saying that the argument is subtle.

Usually you want JOIN nothing in NoSQL, so I'm completely with you in the last paragraph.

+4
source

Whenever you try to create a document, try to consider this:

  • Whether parts of the document require separate access. If so, create a reference document, and if not, then create an embedded document.

    And if you want to know what to choose, I think you should take a look at this question for MongoDb, but the Embedded vs Referenced Document will help you

+2
source

Inlining or linking is the most common problem I encounter when designing a document structure in the NoSQL world.

In an embedded relationship, child objects were embedded in the parent document. In reference relationships, child entities in separate documents and their parent objects in another document, basically having two (or more) types of documents.

There is no single relationship pattern suitable for everyone. The approach you should use depends on what retrievals and updates should be performed for the data being developed.

1. Do you need to get all the child objects together with the parent objects? If so, use the inline relationship.

2. Does your use case allow you to extract objects separately? In this case, use a relationship template.

In most cases, when I worked, I used the relationship pattern. For example: social graph (profiles with relationship tree), proximity points (proximity search based on GeoJSON), classified listing, etc.

A relationship template is also easier to update and maintain since objects are stored in separate documents.

0
source

Check out this article for CosmosDb:

Data Modeling in CosmosDb

0
source

Source: https://habr.com/ru/post/1270524/


All Articles