Exploring Azure Cosmos DB With Gremlin Graph Database
Exploring Azure Cosmos DB With Gremlin Graph Database
Learn how to quickly create a super cool database with Microsoft Azure CosmosDB using the Graph API, as well as collections using Azure Portal.
Join the DZone community and get the full member experience.Join For Free
Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%!
In this article, we will learn about Azure Cosmos DB. We'll get started with creating an Azure Cosmos DB account with the Graph API. Also, we'll create a graph database and collections using Azure Portal.
- Microsoft Azure subscription
Azure Cosmos DB is Microsoft's globally distributed, multi-modal database with scale at the click of a button. Because it's multi-modal, it supports document, table, and graph values together in a single database.
Azure Cosmos DB provides excellent throughput, latency, availability, and consistency guarantees with comprehensive service-level agreements (SLAs), which, as of now, no other database provider is offering.
Below are the key features of Azure Cosmos DB:
- Turnkey global distribution.
- Multi-level data models.
- Scale on demand.
- High response with lower latency.
- High availability.
- Consistency models.
- Money-back guarantee with SLA.
Cases that are highly distributed, mission-critical, and highly available can be best handled by having Azure Cosmos DB as one of its application architecture components.
Following are a few use cases recommend by experts:
Creating Cosmos DB Using Azure Portal
Open Microsoft Azure Portal. Click + Create New resource > Database > Cosmos DB.
Alternatively, type cosmos db in search text box and click Azure Cosmos DB under services listed as a result.
Enter the following required details to create Cosmos DB:
- ID: This needs to be globally unique. This ID followed by https://documents.azure.com/ presents a URI to play with the service. For this blog, the ID is azure-cosmos-demo. After Amazon Cloud Service is handled, the URI will be https://azure-cosmos-demo.documents.azure.com/.
- API: This is the most important section to be selected. At the time of writing, Cosmos DB supports this five the following five databases, which can be seen in the following image:
For this blog, we will select Gremlin (graph).
- Subscription: Here, you can select any of your multiple subscriptions. For this article, we will select the subscription Free Trial.
- Resource Group: Cosmos DB is part of Azure resources, and hence it needs to be clubbed in with a logical group: the resource group. As per your requirements, select an existing resource or create a new one. For this article, we are creating new resource group: cosmosdb.
- Location: Select as per your predicted user’s geolocation. For this article, we selected East US.
We're not checking geo-redundancy, as Cosmos DB has a cool feature of replicating the database at any geolocation upon a click. We'll look at this in another article.
Pin it to the dashboard and click Create to start the deployment of your service.
We can trace the deployment status in the dashboard. It may take fewer minutes to get deployed.
Once deployed, a notification will pop up and open up the "quick start" section.
Note: It still refers to the service as Microsoft.DocumentDB.
Navigate to the resource: azure-cosmos-demo > Overview.
We can have the URI details, read and write location, subscription, resource group, and many other important details here in this section.
We can enable geo-redundancy here. Also, the data explorer where we can play with the graph database can be navigated to under this section. Refer to the below image and the highlighted area with a green marking.
Another important parameter used for communication with any Azure resources and Azure CosmosDB are keys.
Cosmos DB comes with two types of keys:
Read-write keys: The URI remains the same — primary key, secondary key, primary connection string, and secondary connection string. We can regenerate these keys at any point of time.
Read-only keys: Again with the same default URI, it presents primary key, secondary key, primary connection string, and secondary connection string. We can regenerate these keys at any point of time.
The session is the default consistency for Azure Cosmos DB.
Session consistency is the most widely used consistency level for both single-region and globally distributed applications. It provides write latencies, availability, and read throughput comparable to that of eventual consistency but also provides consistency guarantees that suit the needs of applications written to operate in the context of the user.
You can change the consistency by navigating to Resource > Settings > Default Consistency > Save.
Once updated, it will be notified. It will take a few seconds to update.
For the demo, select EVENTUAL.
Creating Graph Database
Once done creating AN Azure Cosmos DB account with Graph as THE API, let's create our graph database.
For creating a graph database, navigate to Resource > Data Explorer > New Graph.
It will present us with a blade to enter the following details with respect to the graph database:
- Database ID: A database is logical container of one or more collections. Its an identifier for the database. For this article, we will name it demoDatabase.
- Graph ID: A unique identifier for collections under the database. It's also used for ID-based routing through REST and all SDKs. For this article, we will name it demoCollections.
- Storage capacity: This is maximum storage size of the collection. Billing is based on consumptions per GB. We can select it from 10 GB fixed to unlimited. Let's go with 10 GB fixed.
- Throughput: Collections can be provisioned throughputs in request units/second (RU/s). 1 RU corresponds to throughput of a read of a 1 KB document. We can select this in the range of 400-10,000 RU/s. Let's go with a minimum of 400 RU/s. It also displays the estimated hourly cost and daily basis as per the selected throughput.
Note: If you select the storage capacity as unlimited, you can use throughput in the 1,000-100,000 RU/s range. Also, you need to set the partition key for the same.
Once done with entering all fields, click OK to proceed.
In a few seconds, it will create the desired database, which will be listed under Data Explorer.
In this article, we learned how quickly we can create a super cool database with Microsoft Azure CosmosDB. We will create vertices and edges to our graph database in upcoming articles.
Opinions expressed by DZone contributors are their own.