Azure Cosmos DB: Learn by Example

We continue our article series dedicated Microsoft Azure. In previous articles, we’ve talked about Azure SQL Database, SQL Server on Azure VMs, Azure Advisor, etc. In this article, we will talk about what Azure Cosmos DB is, as well as see a simple step by step example on how to enable it and access it from the Microsoft Azure Portal.

 

What is Azure Cosmos DB?

As defined on MS Docs, Cosmos DB is a “is Microsoft’s globally distributed, multi-model database“. As described on Wikipedia, the Greek philosopher Pythagoras first used the term “cosmos for the order of the universe. In Greek, the word is written “κόσμος“. It is not random that this word is used in Azure Cosmos DB. Cosmos DB enables you to store and access data/documents across any number of Azure’s geographic regions. You can easily set your data to easily replicate across data centers all over the world (wherever there is an Azure data center) thus having them globally distributed. This guarantees high throughput, latency, availability, and consistency, based of course on the agreed SLA.

 


Learn more about Azure SQL Database: Enroll to our Online Course!

Check our online course on Udemy titled “Introduction to Azure SQL Database for Beginners
(special limited-time discount included in link).

Our course, will help you get started with Azure SQL Database and SQL Server on Azure Virtual Machines fast and easy. Many live demos included.

Introduction to Azure SQL Database (Online Course - Lifetime Access)
(Lifetime Access, Certificate of Completion and more!)

Learn More


Main Technical Characteristics

The main technical characteristics of Azure Cosmos DB are:

  • Ability to globally distribute your data
  • Multiple data models and APIs for working with your data
  • You can elastically and independently scale throughput and storage on demand and on a worldwide basis
  • Ability to build highly responsive and mission-critical applications
  • Ensure “always on” availability

Learn more

 

How you can Set Up Azure Cosmos DB – A Simple Example

Let’s see a simple example of setting up Cosmos DB in Azure Portal.

Step 1: Create a resource

You create a new resource along with searching for cosmos. As you can see, the “Azure Cosmos DB” resource appeared in the search results.

What is Azure Cosmos DB - Article on SQLNetHub

 

Step 2: Click on the “Create” Button

What is Azure Cosmos DB - Article on SQLNetHub

 

Step 3: Create an Azure Cosmos DB Account

On this page, you enter the basic settings.

What is Azure Cosmos DB - Article on SQLNetHub

 

Next, you specify the network settings.

What is Azure Cosmos DB - Article on SQLNetHub

 

Then, if you you like, you can set tags for categorizing resources (i.e. for billing view purposes).

What is Azure Cosmos DB - Article on SQLNetHub

 

Then, the summary page is presented, where a validation of your settings takes place. In my example, validation was successful.

What is Azure Cosmos DB - Article on SQLNetHub

 

Step 4: Wait for Deployment to Complete

What is Azure Cosmos DB - Article on SQLNetHub

…and right after deployment is completed, you can now access your Azure Cosmos DB accounts.

What is Azure Cosmos DB - Article on SQLNetHub

 


Learn all about MySQL on Azure – Enroll to our Online Course!

Enroll to our online course on Udemy titled “Introduction to Azure Database for MySQL” and get lifetime access to high-quality lessons and hands-on guides about all the aspects of MySQL database service on the Azure cloud platform!

Introduction to Azure Database for MySQL - Online Course
(Lifetime Access, live guides, certificate of completion, downloadable resources and more!)

Enroll with Discount


Step 5: Access your Azure Cosmos DB Account

The next step is to access your Azure Cosmos DB account and see the overview. In the overview page, it is important to see the status of the service. In my example, you can see that the status is “Active”.

That means that the service is ready to be used.

What is Azure Cosmos DB - Article on SQLNetHub

 

Note: In order to have Portal access to your Azure Cosmos DB account and perform certain actions, you might need to update your firewall rules accordingly.

 

Step 6: Working with your Data on Azure Cosmos DB

As mentioned in the “Main Technical Characteristics” section of this article, Azure Cosmos provides multiple data models and APIs for working with your data. For example, currently you can use the below APIs (more APIs are coming soon):

  • SQL API
  • MongoDB API
  • Cassandra API
  • Gremlin API
  • Table API

Similarly, there is a variety of platforms via which you can work with your Azure Cosmos DB account.

 

A Simple To-Do App

In this example, I navigated to “Quick Start” and I chose the .NET platform via which I will work with data on my Azure Cosmos DB account:

What is Azure Cosmos DB - Article on SQLNetHub

 

After choosing the “.NET” platform, I click on the “Create ‘items’ collection” button, and a download appears containing a quick start .NET project which will help me to easily work with data.

What is Azure Cosmos DB - Article on SQLNetHub

I compiled and ran the sample .NET project and a local webpage came up, allowing me to create a simple document on my Azure Cosmos DB account. This project is just a simple example (i.e. a to-do app) for just illustrating how easy is to access your Azure Cosmos DB account from a client, in this case, a .NET program.

Here’s the first page of the sample program:

What is Azure Cosmos DB - Article on SQLNetHub

 

Now, let’s add an entry:

What is Azure Cosmos DB - Article on SQLNetHub

Entry added:

What is Azure Cosmos DB - Article on SQLNetHub

Checking your Data with Azure Cosmos DB Data Explorer

Now, I navigated back to the Azure Portal, and via my Cosmos DB account, I clicked on the “Data Explorer” link.

Then, via a simple SQL statement, I can see that the data (1 record) I previously added using the .NET app, is there and available:

What is Azure Cosmos DB - Article on SQLNetHub

 

High Availability – Replicate Data Globally

Now here’s the cool stuff!

When you click on the “Replicate data globally” link, the World map is presented (remember the explanation of the word “cosmos”? 🙂

On this map, you can see the regions (that is the available Azure data centers) in which my data is currently located. The regions are categorized as “Write” and “Read” regions.

Currently, my data is only available on one data center, that is “West Europe” (Write Region).

What is Azure Cosmos DB - Article on SQLNetHub

Now, see how easy is to replicate your data to another region!

I have just clicked on the “North Europe” data center and clicked on the “Save” button.

After you click “Save”, your Azure Cosmos DB data starts replicated to the newly added region. In my example below, you can see that North Europe is being set as a Read Region.

What is Azure Cosmos DB - Article on SQLNetHub

 

A few minutes later, replication is completed, and as you can see, my data is now available on two regions/data centers:

What is Azure Cosmos DB - Article on SQLNetHub

 

Conclusion

Azure Cosmos DB is a globally distributed, powerful multi-model database. Along with the proper SLA, this guarantees high throughput, low latency, as well as high availability and consistency.

In this article, we talked about what Azure Cosmos DB is and discussed its main characteristics. We also went throughout the process of create and accessing and Azure Cosmos DB account via a comprehensive step-by-step example with screenshots. Moreover, we saw how easy it is set global replication for your data.

In subsequent articles, we will explore more Cosmos DB as well as other cool Azure/Cloud data technologies.

Stay tuned!

 

See More! Enroll to the Online Course!

Learn more about Azure SQL Database and get started fast and easy! Through our online course, you will get lifetime access to a comprehensive set of lectures and live demonstrations that will get you started with Azure SQL Database in no time! The course is regularly updated with additional educational material!

Introduction to Azure SQL Database (Online Course - Lifetime Access)
(Lifetime Access/ Live Demos / Downloadable Resources and more!)

Learn More

 

 

Watch the Video Preview of our Online Course “Introduction to Azure SQL Database for Beginners”:

 

Featured Online Courses:

 

Read Also

 

Check our latest software releases!

Easily generate SQL code snippets with Snippets Generator!

Convert static T-SQL to dynamic and vice versa with Dynamic SQL Generator.

Secure your SQL Server instances with DBA Security Advisor.

Benchmark SQL Server memory-optimized tables with In-Memory OLTP Simulator.

 

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)

Loading...

Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub

 



 

What is Azure Cosmos DB? Click to Tweet