Azure Cosmos DB - Poc
Azure Cosmos DB - Poc
Azure Cosmos DB - Poc
Introduction
Azure Cosmos DB is a multi-model PaaS offering on Microsoft Azure. It is a NoSQL globally distributed highly available
database system with less than 10ms of latency for both reads and writes.
Azure Cosmos DB is a new globally distributed database. It can easily be scaled out (horizontally partitioning), and it is
widely available around the world.
Table API
SQL API
API for MongoDB
Cassandra API
Gremlin API
Azure Cosmos DB is a fully managed NoSQL database for modern app development. Single-digit millisecond response
times, and automatic and instant scalability, guarantee speed at any scale. Business continuity is assured with SLA-
backed availability and enterprise-grade security. App development is faster and more productive.
1
Sensitivity: Internal
Cosmos Cost Management
To begin using Azure Cosmos DB, you should initially create an Azure Cosmos account in your
Azure resource group in the required subscription, and then databases, containers, items under it.
Azure Cosmos account contains a unique DNS name and you can manage an account by using the
Azure portal or the Azure CLI, or by using different language-specific SDKs.
Azure Cosmos DB offers multiple database APIs, which include the Core (SQL) API
Core (SQL) API stores data in document format. It offers the best end-to-end experience as we have
full control over the interface, service, and the SDK client libraries.
Azure Cosmos DB SQL API accounts provide support for querying items using the Structured Query
Language (SQL) syntax, one of the most familiar and popular query languages to query JSON
objects.
1
Sensitivity: Internal
Azure Cosmos DB resource model
Azure Cosmos database is the unit of management for a set of Azure Cosmos containers
Container is horizontally partitioned and then replicated across multiple regions. The items that you
add to the container are automatically grouped into logical partitions, which are distributed across
physical partitions, based on the partition key. The throughput on a container is evenly distributed
across the physical partitions.
Azure Cosmos item can represent either a document in a collection, a row in a table, or a node or
edge in a graph
The following image shows the hierarchy of different entities in an Azure Cosmos DB account
1
Sensitivity: Internal
Create Azure Cosmos DB account
Let’s quickly jump to the Azure portal and quickly create a Cosmos DB account. Search for Azure Cosmos DB and
click Add. This will bring you to a new Create Azure Cosmos DB Account window. Provide in detail like the
Resource Group, Account Name, API – Core (SQL), Location, etc. and click on Review + create.
1
Sensitivity: Internal
Different entities in an Azure Cosmos DB account
1
Sensitivity: Internal
Using .NET SDK to manage Azure Cosmos DB SQL API account resources
For setting up a project that uses .NET SDK to manage the Azure Cosmos DB SQL API account
resources, the following are the .NET classes to interact with the resources
This method creates (if it doesn't exist) or gets (if it already exists)
a container as an asynchronous operation. You can check the
status code from the response to determine whether the
container was newly created (201) or an existing container was
CreateContainerIfNotExistsAsync returned (200).
CreateItemAsync This method creates an item within the container.
This method creates an item within the container if it doesn't
UpsertItemAsync already exist or replaces the item if it already exists.
This method creates a query for items under a container in an
Azure Cosmos database by using a SQL statement with
GetItemQueryIterator parameterized values.
ReplaceFamilyItemAsync This method replace an item in the container
This method deletes the specified database from your Azure
DeleteAsync Cosmos account.
1
Sensitivity: Internal
Server Side Programming – Stored Procedure
For partitioned containers, when executing a stored procedure, a partition key value must be
provided in the request options. Stored procedures are always scoped to a partition key. Items that
have a different partition key value will not be visible to the stored procedure.
1
Sensitivity: Internal
Azure Cosmos DB POC – Tasks performed
1
Sensitivity: Internal
Sensitivity: Internal