Microsoft Azure Cosmos DB Revealed: A Multi-Model Database Designed for the Cloud
()
About this ebook
Microsoft Azure Cosmos DB Revealed demonstrates a multitude of possible implementations to get you started. This book guides you toward best practices to get the most out of Microsoft’s Cosmos DB service. Later chapters in the book cover advanced implementation features, helping you master important elements such as securing the database, querying, and using various APIs.
What You'll Learn
- Set up a development environment to work with Azure Cosmos DB
- Configure Azure Cosmos DB in a production environment with multi-region distribution
- Query using all APIs, including SQL, JavaScript, MongoDB, and Graph
- Work with the Azure Cosmos DB.NET SDK in an application you built
- Access Cosmos DB from web applications created in .NET
Developers who build applications to be hosted in Microsoft Azure, whether they use PaaS or IaaS. No previous knowledge of Azure Cosmos DB is assumed, but readers must be familiar with developing applications in Microsoft Visual Studio.
Related to Microsoft Azure Cosmos DB Revealed
Related ebooks
Practical Azure SQL Database for Modern Developers: Building Applications in the Microsoft Cloud Rating: 0 out of 5 stars0 ratingsCosmos DB for MongoDB Developers: Migrating to Azure Cosmos DB and Using the MongoDB API Rating: 0 out of 5 stars0 ratingsUnderstanding Azure Data Factory: Operationalizing Big Data and Advanced Analytics Solutions Rating: 0 out of 5 stars0 ratingsLearning Azure DocumentDB Rating: 0 out of 5 stars0 ratingsGuide to NoSQL with Azure Cosmos DB: Work with the massively scalable Azure database service with JSON, C#, LINQ, and .NET Core 2 Rating: 0 out of 5 stars0 ratingsCreating ASP.NET Core Web Applications: Proven Approaches to Application Design and Development Rating: 0 out of 5 stars0 ratingsData Science Solutions on Azure: Tools and Techniques Using Databricks and MLOps Rating: 0 out of 5 stars0 ratingsPro Oracle Database 18c Administration: Manage and Safeguard Your Organization’s Data Rating: 0 out of 5 stars0 ratingsManaging PeopleSoft on the Oracle Cloud: Best Practices with PeopleSoft Cloud Manager Rating: 0 out of 5 stars0 ratingsDevOps for Databases: A practical guide to applying DevOps best practices to data-persistent technologies Rating: 0 out of 5 stars0 ratingsIntroducing Microsoft SQL Server 2019: Reliability, scalability, and security both on premises and in the cloud Rating: 0 out of 5 stars0 ratingsImplementing Power BI in the Enterprise Rating: 5 out of 5 stars5/5HDInsight Essentials - Second Edition Rating: 0 out of 5 stars0 ratingsActive Directory with PowerShell Rating: 4 out of 5 stars4/5Generic Pipelines Using Docker: The DevOps Guide to Building Reusable, Platform Agnostic CI/CD Frameworks Rating: 0 out of 5 stars0 ratingsDevSecOps for Azure: End-to-end supply chain security for GitHub, Azure DevOps, and the Azure cloud Rating: 0 out of 5 stars0 ratingsBuilding Scalable Apps with Redis and Node.js Rating: 0 out of 5 stars0 ratingsGetting Started with DuckDB: A practical guide for accelerating your data science, data analytics, and data engineering workflows Rating: 0 out of 5 stars0 ratingsGetting Started with SQL Server 2014 Administration Rating: 0 out of 5 stars0 ratingsBeginning PostgreSQL on the Cloud: Simplifying Database as a Service on Cloud Platforms Rating: 0 out of 5 stars0 ratingsGo for DevOps: Learn how to use the Go language to automate servers, the cloud, Kubernetes, GitHub, Packer, and Terraform Rating: 0 out of 5 stars0 ratings
Databases For You
Blockchain Basics: A Non-Technical Introduction in 25 Steps Rating: 5 out of 5 stars5/5COMPUTER SCIENCE FOR ROOKIES Rating: 0 out of 5 stars0 ratingsPractical Data Analysis Rating: 4 out of 5 stars4/5A Concise Guide to Object Orientated Programming Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Go in Action Rating: 5 out of 5 stars5/5Access 2019 For Dummies Rating: 0 out of 5 stars0 ratingsLearn SQL in 24 Hours Rating: 5 out of 5 stars5/5Excel 2021 Rating: 4 out of 5 stars4/5Getting Started with SQL Server 2014 Administration Rating: 0 out of 5 stars0 ratingsSQL Server: Tips and Tricks - 2 Rating: 4 out of 5 stars4/5Access for Beginners: Access Essentials, #1 Rating: 0 out of 5 stars0 ratingsLearn Data Analysis with Python: Lessons in Coding Rating: 0 out of 5 stars0 ratingsRaspberry Pi Server Essentials Rating: 0 out of 5 stars0 ratingsBehind Every Good Decision: How Anyone Can Use Business Analytics to Turn Data into Profitable Insight Rating: 5 out of 5 stars5/5Access 2010 All-in-One For Dummies Rating: 4 out of 5 stars4/5Advanced Analytics in Power BI with R and Python: Ingesting, Transforming, Visualizing Rating: 0 out of 5 stars0 ratingsLearn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5Learn Git in a Month of Lunches Rating: 0 out of 5 stars0 ratingsLearn dbatools in a Month of Lunches: Automating SQL server tasks with PowerShell commands Rating: 0 out of 5 stars0 ratingsOracle APEX Tips and Tricks: II Rating: 0 out of 5 stars0 ratingsAccess 2016 For Dummies Rating: 0 out of 5 stars0 ratingsLearning Oracle 12c: A PL/SQL Approach Rating: 0 out of 5 stars0 ratingsVisualizing Graph Data Rating: 0 out of 5 stars0 ratingsPython and SQLite Development Rating: 0 out of 5 stars0 ratings
Reviews for Microsoft Azure Cosmos DB Revealed
0 ratings0 reviews
Book preview
Microsoft Azure Cosmos DB Revealed - José Rolando Guay Paz
© José Rolando Guay Paz 2018
José Rolando Guay PazMicrosoft Azure Cosmos DB Revealedhttps://doi.org/10.1007/978-1-4842-3351-1_1
1. Introduction to Azure Cosmos DB
José Rolando Guay Paz¹
(1)
Beach Park, Illinois, USA
The database space has been greatly dominated by relational database management systems (or RDBMSs) such as Microsoft® SQL Server or Oracle. This dominance was made possible in part by the wide range of solutions that can be built on top of those systems but also because of the powerful products that are available. There is, however, a different approach to data management, commonly known as NoSQL. The term NoSQL stands for non SQL
or not only SQL
since SQL (Structured Query Language) is almost exclusively tied to relational systems. NoSQL databases have existed since the 1960s but it wasn’t until the early 2000s that they gained a lot of popularity with companies like Facebook and Amazon implementing them and products such as MongoDB, Cassandra, and Redis becoming the choices for many developers.
In this chapter, I will introduce Azure Cosmos DB, Microsoft’s NoSQL database, which is available in Microsoft Azure as a globally distributed, multi-node database service. We will examine what it is and its main features, but most importantly, at the end of the chapter, you will have a complete development environment that you can use for your applications.
What Is Azure Cosmos DB?
Azure Cosmos DB started in 2010 as an internal Microsoft project known as Project Florence.
The objective of the project was to address some of the problems that the Microsoft developers were facing with large Internet-scale applications . In 2015, the project was made available to external developers in Microsoft Azure and a new product was born under the name of DocumentDB. Finally, at the Microsoft Build 2017 conference, Azure Cosmos DB was officially launched with existing DocumentDB capabilities such as global distribution and horizontal scale with low latency and high throughput.
What’s new in Azure Cosmos DB is that it natively supports multiple data models: key-value, documents, graph, columnar, and more that are currently being developed. This gives you the freedom to work with your data in the form that best describes it. It also supports multiple APIs for accessing data including DocumentDB SQL, MongoDB, Apache Cassandra, Graph, and Table.
Major Features
The following are some of the most important features of Azure Cosmos DB. There are many features in the product, but what follows are the ones that drove the implementation. They are what the product developers most had in mind. Most of these features were present since DocumentDB; however, with the evolution of the product, new features were introduced, making Azure Cosmos DB what is now. Many more features are under development.
Turnkey Global Distribution
Global distribution means that your databases can be distributed across different regions of Microsoft Azure and can be stored and accessible closer to your clients. This powerful functionality has a high degree of automation and performance. There is no need to handle complex configurations, replication downtime, high latency, or security concerns. Using the Microsoft Azure portal, all you need to do is select the regions where the database will be distributed and the portal will do the rest.
Multiple Data Models and APIs
With Azure Cosmos DB, you can select the data model that best represents your data. There is no need to think in terms of a rigid structure for the data. If, for example, you want to store user settings, you can use the key-value data model; if you want to work with orders, products, and payments, you can use a document data model. If your data is best described as relations between entities, then use a graph data model.
The DocumentDB API provides familiar SQL query capabilities. If you have an application built on MongoDB, you can use the MongoDB API transparently; in many cases there is no need to rewrite the application, only change the connection string. For key-value databases, you can use the Table API, which provides the same functionality as Azure Table storage but with the benefits of the Azure Cosmos DB engine. With the Graph API , you can use the Apache TinkerPop graph traversal language, Gremlin, or any other TinkerPop-compatible graph system like Apache Spark GraphX.
Elastically Scale Throughput and Storage on Demand
Throughput in Azure Cosmos DB can be configured in requests per second based on the requirements of your application. You can also change this configuration at any time.
You can use all the storage you need. There are no caps as to how much data you can store. Also, scaling databases is transparent and happens automatically based on the configuration you set for your account.
High Availability and Response Time
Azure Cosmos DB has a standing SLA of 99.99% availability and a latency in the 99th percentile regardless of the region. It also provides a guaranteed throughput and consistency.
Five Consistency Models
Azure Cosmos DB provides five different consistency models , from strong SQL-like consistency to NoSQL-like eventual consistency. It all depends on what your business or application needs.
Setting Up the Development Environment
To develop applications with Azure Cosmos DB, I recommend using Microsoft Visual Studio 2017. The main reason for this recommendation is that it is very easy to build, test, and deploy applications for Microsoft Azure. Another reason is that Visual Studio has a free edition called Visual Studio Community Edition that has all the capabilities we need to develop applications with Azure Cosmos DB.
Installing Microsoft Visual Studio
If you already have Visual Studio 2017 installed, you can skip this section.
To obtain Visual Studio, all you need to do is the following:
1.
Open your browser and go to www.visualstudio.com/. The page is shown in Figure 1-1.
2.
From the Download Visual Studio drop-down, select Community 2017. If you have a license for a different edition, you can download it by selecting it from the options.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig1_HTML.jpgFigure 1-1
Download Microsoft Visual Studio 2017
3.
After selecting an edition to download, you will be redirected to a new page where your download will start.
4.
Save the installer file in a folder by clicking the Save button, as shown in Figure 1-2.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig2_HTML.jpgFigure 1-2
Save the installer file to a folder
5.
After the download has completed, run the installer file by clicking the Run button shown in Figure 1-3.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig3_HTML.jpgFigure 1-3
Run the installer file
6.
You may be prompted to authorize the file to run. Select Yes in the prompt window.
7.
The first window in the installation program (shown in Figure 1-4) will show you links to read the Microsoft Privacy Statement as well as the license terms. Accept the license terms by clicking the Continue button.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig4_HTML.jpgFigure 1-4
Visual Studio license terms and privacy statement window
8.
Once you click the button, the installation program will download the most current list of options to install, as seen in Figure 1-5.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig5_HTML.jpgFigure 1-5
Downloading installation options
9.
After the options are downloaded, they will be displayed so you can select the necessary components for the types of applications you will develop. Figure 1-6 shows these components. In this case, you will select ASP.NET and web development and Azure development.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig6_HTML.jpgFigure 1-6
Selecting Visual Studio components to install
10.
Leave the default location to copy the files and click the Install button.
11.
The program will start downloading the necessary files from Microsoft and install Visual Studio, as shown in Figure 1-7.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig7_HTML.jpgFigure 1-7
Downloading and installing Visual Studio Community 2017
12.
Once the installation has completed, you will need to restart your PC. Figure 1-8 shows the window requiring you to restart your PC. You can choose to do so later but it is not recommended to try to launch Visual Studio before restarting the PC .
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig8_HTML.jpgFigure 1-8
Restart your PC after installation has completed
13.
Figure 1-9 shows Visual Studio’s welcome window. After you restart, you can launch Visual Studio. It will ask you to sign in with a Microsoft account such as an Outlook.com or Office 365 account.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig9_HTML.jpgFigure 1-9
Sign in with a Microsoft account
14.
Next, you will be asked to configure some settings for Visual Studio, as shown in Figure 1-10. For the development settings, select Web Development. For the color theme, choose the color you like the most.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig10_HTML.jpgFigure 1-10
Visual Studio’s welcome window and environment settings
15.
That’s it. You now have Visual Studio installed and running.
Installing the Azure Cosmos DB Emulator
With Azure Cosmos DB Emulator, you can develop your application locally on your own computer without creating an Azure subscription or incurring any costs. Once the application is ready for deployment, all you need to do is to switch to an Azure Cosmos DB subscription.
The emulator has some requirements before it can be installed:
It will only run on Windows 10, Windows Server 2012 R2, or Windows Server 2016.
It needs 2GB of RAM and at least 10GB of free disk space for storage.
To install the emulator, use the following instructions:
Using your browser, download the emulator installer from https://aka.ms/cosmosdb-emulator.
Save the installer file in a folder, as shown in Figure 1-11.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig11_HTML.jpgFigure 1-11
Download and save the installer file
After the download is complete, run the installer file as shown in Figure 1-12.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig12_HTML.jpgFigure 1-12
Run the installer file
Figure 1-13 shows the first window in the installation program. Check the box to accept the license agreement and click the Install button.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig13_HTML.jpgFigure 1-13
Accept the license agreement and click the Install button
You may be prompted to authorize the file to run. Select Yes in the prompt window.
The installation will happen very quickly and then the final window will give you the option to launch the emulator. Check the box to launch the emulator and then click the Finish button, as shown in Figure 1-14.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig14_HTML.jpgFigure 1-14
Installation of the Azure Cosmos DB Emulator is complete
After you click the Finish button, the emulator starts and launches the web interface (shown in Figure 1-15). This will indicate that the installation was successful.
../images/455488_1_En_1_Chapter/455488_1_En_1_Fig15_HTML.jpgFigure 1-15
Azure Cosmos DB Emulator web interface
With these tools, you have now set up a development environment to create applications that use Azure Cosmos DB.
Creating a Microsoft Azure Account and Subscription
Microsoft has made the process of creating an Azure account very easy. The account will give you access to Azure, but in order to use the products you must also create a subscription. The subscription you will create now is based