Document DB

Azure Cosmos DB – 429 Too Many Requests

October 6, 2018 .NET, Azure, CosmosDB, Document DB, Microsoft, Performance, Reliability, Resilliancy, Scalability, Visual Studio 2017, VisualStudio, VS2017 No comments

Recently while I was doing Performance Testing in one of the APIs interacting with Cosmos DB, I encountered a problem as Azure Cosmos DB API’s started returning Http Code 429.  Http Status Code 429 indicates that too many request been received or request rate is very large. This error would happen when we have concurrent users trying to write or read from same cosmos db collection.

Following diagram covers the architecture of the performance test I am performing:

image

Based on analysis it found out to be the Throttling happening from Azure Cosmos DB, as we make requests that may use more than provisioned Request Units(RU) per second. We were using default Cosmos DB configuration for a fixed collection of 1000 RU’s per second which is sufficient enough for a 500 reads and 100 writes for a 1 kb file. You can refer more about Request Units from Azure Docs.

image

 

 

 

Solution(s):

1. Now first logical step we can do is to get rid off this error by increasing the Throughput for the collection.  I am going to increase to 10000 RU/s maximum allocatable for a Storage Capacity: Fixed.   This should ideally improve the Throughput for 250 or more virtual users hitting.

image

2. Second logical step is to improve the code: Improve the connection parameters in the Document DB SDK –> DocumentDbClient. For this I referred to the Microsoft Docs: Performance tips for Azure Cosmos DB and .NET

Providing optimum values to the following Properties in RetryOption class   to be passed as parameter to Connection Policy.

image

 

In my case I provided a value of 30 to give ultimate results:

new RetryOptions() { MaxRetryAttemptsOnThrottledRequests = 30, MaxRetryWaitTimeInSeconds = 30  }

That should resolve most of the 429 issues when dealing with Cosmos DB SDK

Azure Cosmos DB name changes

April 17, 2018 Azure, CosmosDB, Document DB, Emerging Technologies, Microsoft, Windows Azure Development No comments

An update from Microsoft Azure says that – As part of the transition from Azure DocumentDB to Azure Cosmos DB, the service and resource names are changing from “Azure DocumentDB” to “Azure Cosmos DB” on June 1, 2018.

How does that Impact?

When Microsoft introduced Cosmos DB, then have ensured that there was a smooth transition or migration of existing Document DB customers /tenants to Cosmos DB. This was achieved by without changing underlying service and resource names from “Document DB” to “Cosmos DB”.

So, if you were an existing customer of Document DB, you have noticed the only disappearance of Document DB name and old service showing simply Cosmos DB. You did not feel much difference apart from some additional configuration options as part of multi-modal data source configuration.

Your ARM deployment templates might need some changes in resource sizing, resource location, and some other configuration aspects.

There is no a pricing impact because of this change, but you will have to modify billing parameters that rely on the new names. Now with this deadline what Microsoft intends to have is to deprecate the use of Old DocumentDB naming and start migrating all customers/tenants to follow the new naming for the resource billing/sizing purposes.

To read more about the naming changes: https://azure.microsoft.com/en-us/updates/name-changes-cosmos-db/

Getting Started local development with Azure Cosmos DB services – Part 2

May 29, 2017 .NET, .NET Core 1.0, .NET Core 1.0.1, .NET Framework, ASP.NET, Azure, Azure SDK Tools, Azure Tools, Cloud Computing, CodeSnippets, CosmosDB, Document DB, Microsoft, PaaS, SaaS, Visual Studio 2015, Visual Studio 2015 Update 3, Visual Studio 2017, VisualStudio, VS2015, VS2017, Windows, Windows 10, Windows Azure Development, Windowz Azure No comments

In my previous article we discussed about setting local development environment using Cosmos DB Emulator for Windows. With this part 2 of the article, we will cover developing, debugging and integration related aspects of using Cosmos DB Emulator.

Developing with Cosmos DB Emulator

Once you have Cosmos DB emulator installed and running on your machine, you can use any supported Cosmos DB SDK or Cosmos DB REST API to interact with emulator. This process is same as you are using a Cosmos DB cloud service.

Cosmos DB Emulator also provides a build-in visual explorer through which you can view,create and edit collections and documents.

image

Before you integrate Cosmos DB SDK or Cosmos DB REST API you would need to generate master key for authentication. Unlike cloud service, Cosmos DB emulator only support single fixed account and master key.  You would not be able to communicate with Emulator without this master key.

Default Master Key:

Account name: localhost:<port>

Account key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

PS: This key is only to be used in Emulator. You cannot use the same key for Production(Cosmos DB Cloud Service).

Furthermore, if you want to set your own key. You can go to command line references and run DocumentDB.Emulator.exe with sufficient command switch to set your own key. Remember it should meet the key security requirements. See command-line tool reference for more information.

The Azure Cosmos DB Emulator is installed by default to the C:\Program Files\Azure Cosmos DB Emulator  or C:\Program Files\DocumentDB Emulator  directory.

Once you have account name and key, you are good to go with development and debugging using Azure Cosmos DB emulator.

Let us start looking at how to use CosmosDB SDK. Once you add Cosmos DB SDK for .NET from NUGET sources. You would need to import the following namespaces to reference necessary classes.

<br />
 using Microsoft.Azure.Documents;</p>
<p> using Microsoft.Azure.Documents.Client;</p>
<p> using Microsoft.Azure.Documents.Linq;<br />

Simple code to establish connection:

<br />
// Connect to the Azure Cosmos DB Emulator running locally use DocumentClient class in :<br />
DocumentClient client = new DocumentClient(<br />
    new Uri(&quot;https://localhost:8081&quot;),<br />
    &quot;C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==&quot;);<br />

In the above code block we are directly embedding endpoint, key in the source code.But as a suggested approch keeping in mind to easily point to production service would be maintain the key in Web.config appSettings.

<br />
   &lt;add value=&quot;https://localhost:8081/&quot; key=&quot;endpoint&quot;/&gt;<br />
    &lt;add value=&quot;C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==&quot; key=&quot;authKey&quot;/&gt;<br />
 

Add NuGet reference to Microsoft.Azure.DocumentDB  (always use the latest version of the library)

image

For the ease of this article, I am going to use the existing ToDoList sample from DocumentDB Samples provided by Microsoft. You can originally find the same source from C:\Program Files\DocumentDB Emulator\Packages\DataExplorer\quickstart.

image

Copy and Unzip DocumentDB-Quickstart-DotNet.zip and open todo.sln in Visual Studio 2017 and your solution structure will look like below:

image

Now run the application in your Visual Studio.

1. You will see an initial screen:

image

2. Click on Create New:

image

3. New record will be added to your Azure Cosmos DB Emulator:

image

4. To verify in Cosmos DB emulator now open Cosmos DB explorer, click on Collections and Select ToDoList

image

5.Expand Documents and select item with id:da305da3-c1dc-4e34-94d9-fd7f82d26c58

image

Hope this article was helpful for you with initial development.  Share your feedback through comments and share this to your friends and colleagues.

Useful Links:

Getting Started local development with Azure Cosmos DB services – Part 1

May 20, 2017 .NET, Azure, Azure SDK, Azure SDK Tools, Azure Tools, Cloud Computing, Computing, CosmosDB, Data Services, Document DB, Emerging Technologies, KnowledgeBase, Microsoft, PaaS, Visual Studio 2013, Visual Studio 2015, Visual Studio 2017, VS2013, VS2015, VS2017, Windows 10, Windows Azure Development, Windows Server 2012 R2, Windows Server 2016, Windowz Azure 1 comment , ,

Azure Cosmos DB is a multi-API, multi-model highly scalable NoSQL database services from Microsoft Azure platform. In order to develop an application consuming Azure Cosmos DB requires an azure live subscription or emulator in your local machine.

The Azure Cosmos DB Emulator provides a local development/test environment for Azure Cosmos DB development purposes. Using Azure Cosmos DB Emulator, you can develop and test your application locally, without needing an azure subscription or without subscription costs.

With this article I am going to take you through necessary steps and requirements to set up your local environment.

1. Pre-Requisites:

Azure Cosmos DB emulator has the following software and hardware requirements:

  • Software requirements
    • Windows Server 2012 R2, Windows Server 2016, or Windows 10
  • Minimum Hardware requirements
    • 2 GB RAM
    • 10 GB available hard disk space

2. Installation:

  • Download Azure Cosmos DB Emulator   (DocumentDb.Install.msi)   ** do not get confused by the name. Azure Cosmos DB is a super set of Document DB, and the DocumentDb emulator they tweaked a bit to support Cosmos Db.
  • Install DocumentDb.Install.msi

Additionally Azure CosmosDB emulator can be run on Docker for Windows. After installing Docker for Windows, you can pull the Emulator image from Docker Hub.

docker pull microsoft/azure-documentdb-emulator

imageimageimage

3. Start/Launch Azure Cosmos DB Emulator:

image image

After some time you can see the emulator started. When the Azure Cosmos DB emulator launches it will automatically open the Azure Cosmos DB Data Explorer in your browser.

The address will appear as https://localhost:8081/_explorer/index.html

Incase you have closed browser and later would like to open the explorer again, you can open the Data Explorer by right clicking on the taskbar menu.

image

image

Now you can write some sample app to try it, or download already created sample applications from Microsoft depending on the preferred platform of your choice.

4. Limitation of Azure Cosmos DB Emulator: (or Differences between Azure Cosmos DB Emulator vs Real Cosmos DB Cloud Service)

Since the Azure Cosmos DB Emulator provides an emulated environment running on a local developer workstation, there are some fundamental differences between the emulator and an Azure Cosmos DB account in the cloud:

The following table is also helpful in determining when to use Cosmos DB Emulator and when direct cloud service. Depending on the choice of requirement, you would need to use associated services efficiently.


Cosmos DB Emulator Cosmos DB Cloud Service
Supports only a single fixed account and a well-known master key. Key regeneration is not possible. Supports multiple accounts and different master keys. You can regenerate keys any time from Azure Portal.
Non scalable Highly scalable
Does not support larger data sets Support for large data sets
Does not simulate consistency levels Different Consistency levels available
Does not simulate multi-region replication Configurable as part of the platform, as needed basis.
Does not support quota override feature Supports document size limit increases, increased partitioned collection storage etc.
Might not support most recent changes to Cosmos Db platform Most recent platform update will be available.

Hope this article was helpful for your initial start. If you would need to understand further on Azure Cosmos DB development follow the links. I will be writing further insights in later sessions.

Azure CosmosDB – a multi-model, multi-API for highly scalable applications

May 12, 2017 Analytics, Azure, Cloud Computing, CosmosDB, Data Analytics, Data Services, Document DB, Emerging Technologies, Microsoft, PaaS, Storage, Backup & Recovery No comments

Azure Cosmos DB is the next generation globally distributed multi model database from Microsoft. Cosmos DB has been built from scratch in mind with efficient global distribution and horizontal scalability aspects as the core.

  • Azure Cosmos DB guarantees single-digit-millisecond latencies at the 99% availability across the world with Enterprise Level SLAs.
  • Offers a set of well-defined consistency models to enable high availability.
  • Multi-Model – offers ability to support key-value, graph and document data in one service
  • Multi-API – Azure Cosmos DB automatically indexes all data, and allows you to use your favorite API including SQL, JavaScript, Gremlin, MongoDB and Azure Table Storage to access your data.
  • Elastically scalable and higher throughput.
Data Model API’s
  • Key-value
  • Document
  • Column Family
  • Graph
  • Document DB
  • Mongo DB
  • Table Storage
  • Gremlin Graph
  • Spark

azure-cosmos-db-multimodel

** Azure Cosmos DB is a superset of the existing DocumentDB service, and Microsoft  will be transitioning all existing DocumentDB customers to Azure Cosmos DB, free of charge without data loss.

Read more from: