Last year, I started talking more about my adventures in Azure Cosmos DB. For databases week, I’m going to tackle Azure Cosmos DB in 2 parts – the platform with their SQL API and the rest of the APIs. Why? I know many of my followers have come into the NoSQL realm similar to me – starting in the relational world first. Trying to transition from SQL to NoSQL was a foolish leap for me, similar to earlier in my career when I thought I could move from VB 6 to VB.NET easily. I fell flat on my face in trying to work with the Azure Cosmos DB I had inherited, as the team I joined happened to be using it but were also more familiar with the relational realm. Over the years, I’ve learned plenty of tips and tricks and want to help others get through this hurdle. So let’s see how we can go from relational SQL to NoSQL with Azure Cosmos DB SQL API.
How do we NoSQL when we understand relational SQL?
Before we get into the platform, we need to be clear that Azure Cosmos DB is in the NoSQL realm, not the relational realm that we covered in the MySQL, PostgreSQL, MariaDB, and Azure SQL posts.
Thankfully, the Azure Cosmos DB team knows that there are many of us out there coming from a relational mindset. They have an article that helps us understand the differences between NoSQL and relational databases.
What is Azure Cosmos DB?
Azure Cosmos DB is Microsoft’s NoSQL database offering in Azure. Some of the features of Azure Cosmos DB include:
- Low latency
- Scalable throughput
- Tunable data consistency
- High availability
- Global distribution
- Change feed – such a hidden gem that I’m unhiding it here
When talking about these points, I have to share one of my favorite docs in all of Microsoft’s docs – consistency levels in Azure Cosmos DB. What I love about this doc is:
- It explains the available consistency levels and how they work.
- The animated graphics really demonstrate the consistency levels in action.
- The musician in me loves seeing the musical notes.
There are other features that the Azure Cosmos DB docs showcase. Check out this article that welcomes you to Azure Cosmos DB and gets into more capabilities and features.
Azure Cosmos DB’s SQL is not the relational SQL?
Correct. While their SQL may look similar to the relational SQL, it is indeed different. The data is stored in JSON documents, and querying these JSON documents is different from querying relational tables. Joins in Azure Cosmos DB are done within an item – not across tables or across multiple items. Subqueries in Azure Cosmos DB SQL API are possible, as long as they are referencing values from the outer query. These are just some of the differences in why their SQL for the SQL API is not the same as relational SQL.
What’s this change feed feature?
The change feed is what many of us in the community call a hidden gem. It is a record of changes to the Azure Cosmos DB containers in the order they occur. This article on the Change feed in Azure Cosmos DB gets into more details on how the feed works and which APIs support it.
Azure Cosmos DB Conf is a free, 24-hour virtual conference put on by the Azure Cosmos DB team and their community to showcase their product and its various uses. Check out these sessions from Azure Cosmos DB Conf 2022 that showcase the change feed:
- Implementing Change Data Capture using Azure Cosmos DB Change Feed mechanism
- Azure Cosmos DB Changefeed tales from the trenches
How do I get started?
Here are some links to help you get started with Azure Cosmos DB and their SQL API.
- Microsoft Learn – Get started with Azure Cosmos DB SQL API (learning path)
- Microsoft Learn – Plan and implement Azure Cosmos DB SQL API (learning path)
- Microsoft Docs – Azure Cosmos DB – Getting started with SQL queries
- Microsoft Learn – Consume an Azure Cosmos DB SQL API change feed using the SDK
- Azure Cosmos DB query cheat sheets – especially helpful when writing SQL and realizing this isn’t relational SQL
Bonus: New Community Link!
The Azure Cosmos DB team has a great community presence, as noted by the links included in my Free Azure Services post. However, I recently learned of a newer link to find their community. Check out the Azure Cosmos DB Developer Community!
In case you can’t tell, I am really excited not only about the product but also with the Azure Cosmos DB community. The product team is engaging with the community and truly listening. They support their community members who are out there promoting their product as well. If you’re getting into NoSQL, I highly recommend looking into Azure Cosmos DB.
In the next Learning Azure post, I will talk more about Azure Cosmos DB’s other APIs – allowing us to work with it over APIs for Cassandra, Gremlin, and MongoDB.
[…] yesterday’s post, I included links for getting started with the SQL API. In today’s post, we’re going to look at the other APIs that you can use with Azure […]
[…] Azure Cosmos DB for the Relational Mind and Exploring Additional Azure Cosmos DB APIs (Sarah Dutkiewicz) […]