Home Big-data-and-business-intelligence Learning Azure Cosmos DB

Learning Azure Cosmos DB

By Shahid Shaikh
books-svg-icon Book
Subscription
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
Subscription
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introducing Microsoft Azure Cloud and Cosmos DB
About this book

Microsoft has introduced a new globally distributed database, called Azure Cosmos DB. It is a superset of Microsoft's existing NoSQL Document DB service. Azure Cosmos DB enables you to scale throughput and storage elastically and independently across any number of Azure's geographic regions.

This book is a must-have for anyone who wants to get introduced to the world of Cosmos DB. This book will focus on building globally-distributed applications without the hassle of complex, multiple datacenter configurations. This book will shed light on how Cosmos DB offers multimodal NoSQL database capabilities in the cloud at a scale that is one product with different database engines, such as key-value, document, graph, and wide column store. We will cover detailed practical examples on how to create a CRUD application using Cosmos DB with a frontend framework of your choice. This book will empower developers to choose their favorite database engines to perform integration, along with other systems that utilize the most popular languages, such as Node.js. This book will take you through the tips and trick, of Cosmos DB deployment, management, and the security offered by Azure Cosmos DB in order to detect, prevent, and respond to database breaches.

By the end of this book, you will not only be aware of the best capabilities of relational and non-relational databases, but you will also be able to build scalable, globally distributed,
and highly responsive applications.

Publication date:
May 2018
Publisher
Packt
Pages
168
ISBN
9781788476171

 

Chapter 1. Introducing Microsoft Azure Cloud and Cosmos DB

The public cloud provides services such as virtual private servers and databases hosted as a service to the general public on a subscription basis. Some platforms, such as Amazon, charge an hourly subscription or offer pay-as-you use (Lambda) services, while others charge a fixed amount for a month, such as DigitalOcean, and so on. The Windows Azure public cloud platform is one of the important pillars of Microsoft's Cloud OS vision that is transforming the traditional data center environment, helping businesses unlock insights in data stored anywhere, enabling the development of a wide range of modern business applications, and empowering IT to support users who work anywhere on any device while being able to manage these devices in a secure and consistent way.

In this chapter, we are going to cover the following points related to Microsoft Azure Cloud and Cosmos DB:

  • Azure features
  • Azure as a service, platform, and infrastructure (SPI)
  • Azure components
  • Getting started with Azure
  • Azure Cosmos DB
  • Azure Cosmos DB features
  • Azure Cosmos DB use cases

Let's get started by explaining the topics one by one.

 

Microsoft Azure Cloud features


One of the famous and simplest quotes about Azure goes as follows:

Windows Azure can be anything you want it to be

Microsoft Azure Cloud provides a wide range of different services. Windows Azure lets you build, deploy, and manage solutions for almost any purpose you can imagine.

Windows Azure is a world of unlimited possibilities. Irrespective of whether you're a large enterprise spanning several continents that has to run server workloads or a small business that needs a website with a global presence, Windows Azure provides a platform for building applications that can leverage the cloud to meet the needs of your business.

Microsoft Azure provides the following key features:

  • Open: Azure provides vast collections of software development kits (SDKs) and tools for various languages in order to build scalable cloud-based applications.
  • Flexible: Whether you are running a small business or a huge, high-end processing system, Windows Azure provides  various services and scalability to help you with all the stages of your business.
  • Microsoft-managed: Microsoft has data centers across three continents—the United States, Europe, and Asia. Microsoft itself manages these data centers instead of hiring third-party people to run these, which most other providers do.
  • Compatible: You can integrate your existing cloud premise with Azure easily using either support teams or tools.
  • CDN: Azure providescontent delivery network (CDN) that consists of a geographically distributed system of servers that enables Windows Azure to deliver high-bandwidth content for performance-sensitive customers by caching data, images, pictures, and video from Windows Azure compute instances.
  • Distributed database: Azure cloud provides easy-to-manage distributed databases such as SQL Server and Cosmos DB to help developers scale and build global range applications.

You can refer to this diagram for all of the components Azure Cloud offers:

Let's dive more into what Azure can do as a serial peripheral interface (SPI).

 

Microsoft Azure as an SPI


There are many cloud computing platforms offered by different organizations such as Google Cloud, Amazon Web Services, and so on. Windows Azure is one of them, and is provided by Microsoft Azure.

Azure is described as the managed data centers that are used to build, deploy, and manage the applications and provide services through a global network. Platform as a service (PaaS) and infrastructure as a service (IaaS) are the services provided by Microsoft Azure. It supports majority of the programming languages.

Azure as PaaS

Azure provides platforms to clients to develop and deploy software without worrying about the server infrastructure and configuration. You can focus on the development of the application and leave the infrastructure worries to Azure.

One of the key perks of using Azure is the overall cost, which is low as the resources are allocated on demand and servers are automatically updated. Azure provides automatic updates to avoid security issues, and it does all that in the background without affecting the application.

Azure as IaaS

Azure provides a managed compute service that gives complete control of the operating systems and the application platform stack to the application developers. It provides developers with control over the data center and allows them to manage it.

This is the ideal case for projects where complete control is required. The virtual machine can be completely altered to the requirements of the project or business. However, if not managed carefully, it could become troublesome; all the security updates then become the job of the developer who manages the infrastructure.

The maintenance of the legacy application also sometimes becomes difficult due to operating system and application stack updates.

 

Azure components


Please refer to the following diagram, consisting of Azure components:

As you can see in the preceding diagram, there are different execution models, in particular the distinctive advancements that can be utilized to execute applications running in the Windows Azure cloud. The execution models mainly consist of the four Windows Azure compute services, websites, cloud services, and mobile services.

At the base are the SDKs for different languages which you can use for building, sending, and overseeing applications that can be kept running on Windows Azure.

The SDKs that are presently upheld incorporate .NET, Java, PHP, Node.js, Ruby, Swift, and Python. There is additionally a general Windows Azure SDK that gives essential help to any programming dialect, for instance C++.

Enough of the theories; let's get started with Azure.

 

Getting started with Azure


To start with Azure, first you need to visit Microsoft Azure and create a new free account or use your existing Hotmail account. The free account comes with a credit and you can use that credit for 12 months. You need to add your credit card information and verify it. Microsoft Azure won't charge you without the required action from the user's side:

When your account is created, log in into the Azure portal. Once your login is successful, you should see a screen similar to the following:

Let's understand the components and functionalities of each module in brief.

Azure components are divided into the following major components:

  • Compute modules
  • Data management modules
  • Networking module
  • Big data module
  • Caching and messaging module
  • Identity module
  • Mobile service module
  • Internet of things

Let's look over each of them.

Compute modules

As the name suggests, the job of this module is to provide a set of tools and services to do computing. Here is the list of services which are provided under compute modules:

As seen in the preceding screenshot, these components mainly consist of virtual machines and containers, but as per the requirements you can join them together as well.

For example, a virtual machine with more disks and snapshots along with containers is used for continuous delivery.

Let's look over the next component, the data management modules.

Data management modules

Data management modules consist of SQL Server, Azure Cosmos DB, Redis, PostgreSQL, and data warehouses. You can deploy these data management modules and use them in your app.

Here is the complete list of data management modules:

We are going to cover Azure Cosmos DB in an upcoming section. Microsoft Azure started to support MySQL and PostgreSQL in the current version (only at the time of writing this book).

Let's look over the networking module.

Networking module

The Azure traffic manager is in charge of directing the request of a user cleverly to an accessible data center. The procedure includes finding the closest data center to the user who makes the demand for the web application, and if the closest data center is not accessible because of different reasons, the traffic manager deviates the demand to another data center.

Be that as it may, rules are set by the administrator of the application regarding how the traffic manager should act in such cases. The virtual network permits a system between nearby machines at your commencing place and a virtual machine in Azure's data center. IPs to virtual machines can be appointed for identity and accessibility purposes. Virtual network setup requires a virtual private network device.

Azure also provides an application gateway which is very useful in micro services application development.

Following is the list of networking modules Azure supports at the time of writing this book:

Let's look over the big data and business intelligence modules.

Big data modules

The extensive measure of data can be stored and retrieved using Windows Azure. Azure offers HDInsight, which is a Hadoop-based service to determine and sense out enormous information stored as big data. Companies regularly need to oversee extensive measures of information which are not fundamentally relational in nature. Hadoop is used by many organizations nowadays, and it is used in Azure too.

In this manner, Azure offers Hadoop benefits on their platform for their customers. The term big compute alludes to high-performing calculations. This is accomplished by executing code in parallel on many machines in the meantime.

The components offered by big data modules are shown in following screenshot:

As you can see, Azure offers big data services ranging from storage using Hadoop clusters to performing analytics over big data, performing log analytics to determine errors, and generating reports based on your data.

Azure also provides machine learning web services to be used as smart algorithms to train and derive sense out of data.

Let's look over the caching and messaging modules.

Caching module

The Windows Azure caching service helps you to build a high-end, scalable, and dedicated cache for your website.

Azure cache is offered in three different types:

  1. Basic: A cache size less than 1 GB comes with this type.
  2. Standard: A cache size ranging from 1 GB to 10 GB comes with this type.
  3. Premium: A cache size more than 5 GB and less than 150 GB comes with this type.

Let's look over the messaging module.

Messaging module

Windows Azure offers two options for handling the interactions between two apps:

  • Message queues
  • Service bus

Generally, service-oriented architecture or SOA-based applications use service buses to perform the communication between various services.

Distributed and independent services, such as micro services, use message queues to perform the communication between them. The developer can choose one according to their needs and requirements.

Let's look over the identity module.

Identity module

This component is all about the administration of users, validation, and authentication/authorization. The active directory stores the data of clients getting to the application and, furthermore, the association's data within the organization. It can synchronize with the related data on nearby machines dwelling on-premises for effective sessions.

Here are the security and identity modules provided by Azure:

Microsoft Active Directory is one of the most mature and popular authentication and authorization modules on the market.

Let's look over the mobile service module.

Mobile service module

Windows Azure offers a simple platform to create portable mobile applications. You can begin the development of your mobile app using the Azure mobile SDK. There are so many libraries already available in Azure SDK such as notification, authentication, and so on. You can focus on your business logic and Azure SDK will help you in the common routines to ship your app faster.

Windows Azure provides a very easy platform to develop mobile applications. You can simply start using mobile development tools after logging in to your account. You don't have to write big custom code for the mobile application if you use this service. The push notifications can be sent, data can be stored, and users can be authenticated in less time.

Please refer to the following screenshot for the full list of mobile service modules:

As you can see, the list of modules is enough for mobile app developers to bootstrap their application quickly and easily.

Let's look over the last, and one of my favorite, modules: the internet of things (IoT)!

IoT modules

IoT is a hot subject right now and Azure is one of the first providers in the cloud market to facilitate such services. IoT modules allow developers to deploy services such as IoT device communication, networking, and device allocation to the hub.

Refer to the following list of modules provided by Azure for IoT purposes:

There are other modules, along with add-ons such as developer tools, monitoring tools, Bing Maps application programming interfaces (APIs), and so on.

I hope this provides you with brief but useful insight into Azure. Let's dive into Azure Cosmos DB now.

 

Azure Cosmos DB


Azure Cosmos DB is Microsoft's globally distributed, multi-model database with scaling at the click of a button. You can scale Azure Cosmos DB across 30+ Azure regions spread across the globe.

It's multi-model, hence it supports document storage, table storage, and graph values all together in a single database. Azure provides excellent throughput, latency, availability, and consistency guarantees with comprehensive service level agreements (SLAs) which, as of now, no other database provider is offering.

Note

SLAs represent the promise on paper. That means Microsoft Azure offers you upper bound time for various features such as latency, failover, and so on. For more information, visit https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/v1_0/.

Here is the featured and introductory representation of Azure Cosmos DB:

Here are the key features and capabilities Microsoft Azure Cosmos DB offers:

  • Turnkey global distribution
  • Multilevel data models
  • Scale on demand
  • High response with less latency
  • High availability
  • Consistency models
  • Money-back guarantee with SLA

Let's look over each of them in brief.

Turnkey global distribution

Azure Cosmos DB is baked with scaling and distribution. Mobility and cloud are the current major sources of computing use and that creates the challenge of high availability with less latency.

Azure Cosmos DB provides an easy way to build and distribute your application across an Azure data center without doing manual work and configuration. Azure automatically replicates your data across a number of data centers available in the Azure network.

We will be covering turnkey distribution in the next chapter in detail.

Let's look over multilevel data models.

Multilevel data models

Azure Cosmos DB supports multiple data models, including document stores, key values, graphs, and tables. Azure offers consistency and high availability across all data models, regardless of their nature, to store the data.

At the time of writing this book, Azure supports APIs for the following models:

  • Document DB API
  • MongoDB API
  • Table API
  • Graph API

The Microsoft team is working to support other data models, if required, and to enhance the existing ones.

We will study the data models in detail in Chapter 3, Cosmos DB Multi-model Databases.

Let's look over the scaling feature of Cosmos DB.

Scale on demand

Azure Cosmos DB introduces a global turnkey feature; using this, you can deploy and scale your application with literally the click of a button. Azure handles every key technical detail such as infrastructure management, replication, traffic diversion, and so on.

Almost every database as a service offers this scaling, so what's new? Azure offers a software level agreement for latency and deployment time, and if it takes more time than promised, you will get your money back!

Let's look over the latency responsiveness of Cosmos DB.

High response with less latency

According to the Azure documentation:

"Azure Cosmos DB guarantees end-to-end low latency at the 99th percentile to its customers."

This is a huge promise. Cosmos DB offers end-to-end latency reading under 10 ms for 1 KB of payload, and write under 15 ms in the same region of Azure. This is very impressive and helpful.

With this high response rate and low latency, let's see how Cosmos DB manages consistency.

Consistency models

Most of the distributed databases offer consistency models, mainly strong and eventual consistency. Azure offers three more consistency levels. They are:

  • Bounded staleness consistency: This guarantees that the read may lag behind the write. This consistency model increases the cost of a read option and is higher than session and eventual consistency.
  • Session consistency: This is ideal for all scenarios in which a user is involved since it needs real-time reads and writes.
  • Consistency prefix: This guarantees that the data written in order will be seen and read in the order that it was performed.

Let's look over the main promise of Azure Cosmos DB, which is its money-back guarantee.

Money-back guarantee and SLA

Azure Cosmos DB promises that your data gets there fast, or they send your money back. Azure Cosmos DB provides service level agreements for availability, latency, throughput, and consistency.

An SLA, as of now, is offered only by Microsoft. You can refer to the complete documentation here: https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/v1_0/.

Let's look over the few use cases of Azure Cosmos DB.

 

Cosmos DB use cases


You can use Cosmos DB in scenarios which are highly distributed, mission critical, highly available, and easy to deploy. The following are the use cases offered by the Microsoft team:

  • IoT
  • Retail and marketing
  • Gaming
  • Web and mobile

Let's look over the use cases briefly.

IoT

IoT consists of various devices that emit data every fraction of a second. This places a need for high ingestion from multiple sources. Azure IoT hub can be used to receive the data from various IoT devices.

Once the data is ingested, you can use Azure HDInsight to process and derive real-time insight. You can then store this data in multiple sources, such as tables, to view in SaaS-based applications, DocumentDB to process the data for graphs and processing, and so on.

Let's look over the next use case.

Retail and marketing

Microsoft uses Azure Cosmos DB in the Microsoft e-commerce platforms Windows Store and Xbox Live. Azure Cosmos DB can be used to store product data, search the products, and perform the session, which is very important for e-commerce applications.

Azure Cosmos DB can also be used for event sourcing using its own change feed functionality. Change feed provides the amazing event generation mechanism to handle micro service communication.

You can refer to the following diagram about micro service communication:

Change feed is a concept introduced by RethinkDB; Packt authored a book on this called Mastering RethinkDB.

Let's look at the next use case, which is my favorite one, gaming.

Gaming

Games are highly mission critical and should be very much available at all times. That requires fast and highly available databases. Azure has already proved its worth in games such as Halo 5, The Walking Dead, and so on. Azure Cosmos DB performance can be used to handle millions of requests and to show real-time data feeds and social engagement.

Azure Cosmos DB provides an API that can be directly used in games, and with the help of database functions such as Hadoop, could be used for real-time analysis and feeds.

Let's look over the web and mobile use case.

Web and mobile applications

Azure provides various sets of tools such as key value stores, traffic manager, gateways, and of course Cosmos DB. These can be used in building social media applications, news feeds, and mobile applications using various frameworks.

Azure machine learning and Hadoop can be used as well to generate personalization reports, feeds, and recommendations, which is an amazing part of any modern application. Since most of the data is stored in JSON, it can be communicated and parsed across various scenarios such as the frontend, mobile, backend, and database.

 

Summary


In this chapter, we learned about the Azure platform and its features. We looked at the services and infrastructure offered by Azure cloud to develop mission critical applications. We also looked over Azure Cosmos DB and its features and use cases.

In the next chapter, we are going to learn more about the Azure turnkey distribution feature which is one of the key selling points of Azure Cosmos DB.

About the Author
  • Shahid Shaikh

    Shahid Shaikh is an engineer, published author, and a blogger. He has written tons of tutorials on Node.js and various databases on his blog. He is a believer in open source and almost all his source code is on GitHub. He has also developed and launched a SaaS product called Spark to handle content sharing automation. Currently, he is building a next-generation email marketing tool called Hashmailer.

    Browse publications by this author
Latest Reviews (1 reviews total)
Not that the content this book is bad, though I would have expected seing more new stuff. Most of content were concepts I was fully aware of, having already found source on the Web and already put them in action. I actually gave a speech on Azure Cosmos DB + Gremlin API in Action at Pass SQL Saturday 2018. [https://www.slideshare.net/DenysChamberland] Amongst one of the demo samples I provided was a refactored version of Anthony Chu's CosmosDB Gremlin Flights which I decided to re-build in Asp.Net Core 2.0 through dotnet CLI and Visual Studio Code. The version is much lighter than original. I also found issues using Microsoft.Azure.Graphs 0.3.1 -preview. Some bugs were reported in float negative value conversion as you would find in latitude and longitude. (-) Negative hyphen were lost in conversion and was later reported as a bug. Microsoft encourages us to use Gremlin.Net from now on though the approach is not 100% polished for production. Bytecode streams are not supported at this stage. So what I'd be interested in seing in any further releases would be more emphasis on Gremlin.Net in combination with Asp.Net Core 2.0 though in a real context sample. Not just same ol' console applications skeleton demo. Microsoft is working on new Nodes JS SDK version and invited developers to share their experience. That may be an interesting asset to cover. So all in all, things move very rapidly. I understand. Though it's often good to take a step back sometimes and analyse if content may be deprecated in a few months or few weeks. I can really complain on the price I paid. So I hope this won't be perceived as negative but mainly a personal professional expert opinion
Learning Azure Cosmos DB
Unlock this book and the full library FREE for 7 days
Start now