You are on page 1of 11

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

Cosmos costs are strictly related to cost of requests.


Request Unit measures the computational cost of each queries
(read/write) and is based on the usage of CPU, memory, IOPS for the
request.
1 RU is the cost to read a document of 1 KB getting it by unique key.
Cosmos allows to define a throughput (i.e. RU per second) value
either on database level or on container level.
Obviously the second allows to optimize the way of we can scale
inside the same database, since we can define different throughput
for each container
• Manually, during the creation, for predictable and stable
workloads.
• Auto scale, during the creation, for unpredictable and variable
workloads. Auto scale working from 10% to 100% of settled max
value.
• serverless, pay per use, without reserved throughput, for spiky
workloads, tests and demos. With autoscale still have to pay the
10% always and anyway requires 1 hour rolling window to evaluate
how to scale
1
Sensitivity: Internal
Azure Cosmos DB

 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 class provides a client-side logical representation for the


Azure Cosmos DB service. The client object is used to configure
CosmosClient and execute requests against the service
This method creates (if it doesn't exist) or gets (if it already exists)
CreateDatabaseIfNotExistsAsync a database resource as an asynchronous operation.

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

 Azure Cosmos DB provides language-integrated, transactional execution of JavaScript. When using


the SQL API in Azure Cosmos DB, we can write Stored Procedures in the JavaScript language that
executed inside the database engine.

CreateStoredProcedureAsync Creates a stored procedure in the Azure Cosmos DB

ExecuteStoredProcedureAsync Executes a stored procedure against a container

Delete a StoredProcedureProperties from the Azure


DeleteStoredProcedureAsync Cosmos DB

 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

 To Insert Huge Data in Cosmos DB to check performance


 Inserting 100 records of Booking JSON with parallel load took 742.3526 milliseconds
 Need to check the performance by inserting 1 lakh records of Booking JSON
 To Retrieve Data using Stored Procedure and to check performance
 Retrieving few properties of a single record from 100 records of Booking JSON took
281.7109 milliseconds
 Analysis in progress to perform Replace / Update / Delete items in Cosmos DB

1
Sensitivity: Internal
Sensitivity: Internal

You might also like