Azure Cosmos DB is a new offering that replaces Azure DocumentDB. Sharon provides an overview of this new service, including the benefits, use cases, and how partitioning provides global distribution.
- [Instructor] Azure Cosmos DB is a globally distributed multimodal database. It's a relatively new offering, as it was only launched at Microsoft Build of May 2017. Your data is globally distributed, and Cosmos DB will automatically index the data for you. And you may hear reference to Azure DocumentDB, this is now morphed into Cosmos DB. The benefits of using Cosmos DB include low latency, allowing for rich queries, and a schema is not required.
In addition, Cosmos DB can be replicated globally, and has limitless scale. And finally, there's a guaranteed SLA of 99.99% for availability, throughput and latency. Cosmos DB supports the following data models: DocumentDB, as we just said, DocumentDB morphed into Cosmos DB, MongoDB, Graph, and Table, both of which are in preview, and we will not be getting into any detail about Graph and Table.
Both document DB and Mongo DB are NoSQL document databases that use JSON data. The schema is not enforced, therefore you are able to quickly query these databases. And these databases are highly scalable. Use cases for Cosmos DB include cataloging data, events and logging, as well as housing user data and user content. We can also use Cosmos DB for mobile, web, gaming, and IoT applications.
Let's take a moment to discuss partitioning, which provides elastic scaling for Cosmos DB. First we have our local distribution layer. Here, the resource partitions are spread across the region. And then we have a global distribution layer, now our resource partitions are replicated. And the best part of this is, it's all handled automatically for you. Let's go ahead and take a look at an example. In our example here, you can see that we have our databases, which are isolated by a partition key, in this case by city.
Each database is first stored locally. This is our local distribution level. These happen to be in the region of US East. The databases are then replicated to other regions. This always ensures that the database is available and easily accessible. The extensible APIs that you can use for Cosmos DB include .NET, .NET Core, Node.js, Java, Python, and MongoDB. So you may be asking yourself, which API should I be using? Well, it would depend.
If you're using .NET, you can use DocumentDB API, the MongoDB API, Graph API, or Table API. Java and Node.js will work with the Document DB APIs, MongoDB APIs, and Graph APIs. Python will only work with the DocumentDB API, and Gremlin, only the Graph API. Let's pop into the demo, and let's create an Azure Cosmos DB. As you can see, we're still in our storage account. This is not where we need to be to create an Azure Cosmos DB.
Go ahead and close out this blade, but I am going to do it from the resource group. We're simply going to click Add, start typing cosmos, select Azure Cosmos DB, I'm going to select the first option, Azure Cosmos DB. Here you'll have some information provided to you about the Azure Cosmos DB service. I'm just going to go ahead and click Create.
And the first thing we need to do is enter an account ID. I've provided the ID of lilazurecosmosdb, LIL being short for LinkedIn Learning. Now we get to go ahead and choose our API. In our example, we're going to go ahead and use MongoDB. Next, select your subscription, your resource group, and your location, and then click Create.
Now, this may take some time to create, so it might be a good time to go and grab a cup of coffee, or grab your lunch. After a few minutes, our Azure Cosmos DB has been created. I'm going to go ahead and close down the Create Azure Cosmos DB blade, and then I'm going to go ahead and close the Everything blade. I'm going to scroll over to our Design Storage Resource Group, and here you'll see that we have our lilazurecosmos database account created.
I'm going to go ahead and launch that. First thing that we should do is probably add a collection. I'm going to go ahead and do so by clicking Adding Collection. First thing I'm going to do is go ahead and add in a collection ID. I'm going to base this off our example that we used in the lesson, and I'm going to go ahead and use Toronto. Next add the option for my storage capacity. Do I want to use a fixed storage capacity at 10 gigabytes, or do I want to select unlimited? For our demonstration today, we're going to go ahead and leave it fixed.
Next, we can go ahead and select our initial throughput capacity, or request units per second. It will default to 1,000, but you can go ahead and increase that or decrease that as required. To reduce latency, you'll scale up, but notice it comes at a cost. Right now, our hourly spend is .08 cents. If I start scaling up, you'll notice that our hourly spend also increases. I'm going to bring that back down.
We can also tun on Request Units Per Minute. And that will fluctuate between 400 and 10,000 request units per second. So I'm going to leave that off for the time being, and here I'm going to go ahead and create a new database. In this case, I'm going to call it Toronto just to keep it simple. And then click OK. It doesn't take long for the collection to be created. And there it is, it's done. We can now see the information about that collection.
Next, if I wanted to turn on Replicate Globally, I could do so under settings, and then I could choose where I wanted to replicate this to. I believe in our example, we had the US West as well as Canada. So we're in Canada Central, let's pop this into a West US just for demonstration, and maybe we'll pop one over into the UK West.
And then we go ahead and click Save. We have only touched the surface of what you can do with Azure Cosmos DB. As Azure Cosmos DB is still a relatively new offering, I'd highly recommend that you explore the Azure website for more details on what you can do with this great service.
- Designing data storage
- Azure Blob storage
- Creating Blob storage using PowerShell
- Azure Cosmos DB
- Securing Azure SQL Database
- Selecting the appropriate storage option
- Virtual machine storage tiers
- Managed vs. Unmanaged disks