CRUD Operations in Cosmos DB

Develop for Azure Storage

Shahzad Mian

Content developer, Datacamp

Create

  • Primary way to communicate with Cosmos DB from an application is through SDKs

Customer signing up

Develop for Azure Storage

Read

  • The app uses the SDK to read their specific document by its unique ID

customer checking rewards balance

Develop for Azure Storage

Update

  • The app finds their document and updates the points value from 100 to 0.

Customer using points balance

Develop for Azure Storage

Delete

  • Backend process uses the SDK to permanently delete their document from the container.

Customer deleting profile

Develop for Azure Storage

Choosing Your Consistency

  • Consistency level choice - determines how quickly data changes are visible across locations.

Globe image with london and tokyo

Develop for Azure Storage

Strong

  • Strong - perfect accuracy, all locations must confirm before update is visible
  • Slowest; ideal for financial transactions.

strong consistency

Develop for Azure Storage

Boundless staleness

  • Predictable and reliable reads.

Gemini_Generated_Image_l6c590l6c590l6c5.jpeg

Develop for Azure Storage

Session

  • Default and most popular option.
  • Instantly readable.
  • Consistent experience.
  • Perfect for live user-centric applications.

Session application

Develop for Azure Storage

Consistent prefix

  • Changes always seen in the right order they were made.
  • Not all changes are seen if they are made quickly.

  • Correct sequence:

    • A few seconds behind the latest action.

Gemini_Generated_Image_qnfs4mqnfs4mqnfs.jpeg

Develop for Azure Storage

Eventual

  • Weakest level.
  • No guarantee on timing or order.
  • Lowest latency.
  • Highest availability.

  • Great for non critical data.

Eventual consistency

Develop for Azure Storage

Fine tuning behavior

Choosing the right consistency level

Develop for Azure Storage

Let's practice!

Develop for Azure Storage

Preparing Video For Download...