+44 (0)20 3051 3595 | info@coeo.com | Client portal login

First Steps with Cosmos DB, Building your Own Rocket

Raul Gonzalez

In my previous post, I talked about how No-SQL databases are different from relational ones, now I’m going to show you how to get started building your first No-SQL database using Cosmos DB.

01_first_steps_in_Cosmos_DB

Where to Start

Considering that Azure Cosmos DB is “Microsoft's globally distributed, multi-model database service for operational and analytics workloads. It offers multi-mastering feature by automatically scaling throughput, compute, and storage.”, the natural start point is the Azure Portal.

You obviously need an Azure subscription to be able to create a Cosmos DB account, but if you don't, there is another option most people don’t know about, the Cosmos DB emulator.

Cosmos DB Emulator

The offline version of Cosmos DB is available to download for free and it is used for local development. Currently all available API’s (SQL, Cassandra, MongoDB, Gremlin and Table) can be used with this tool, however, the interface only allows us to query our data using the SQL API.

Once you have downloaded the tool from the link provided in Books Online, installing it is just a couple of clicks, literally.

The emulator provides a web interface that looks pretty much like the Azure Portal.

02_first_steps_in_Cosmos_DB_emulator

Don’t worry about my key, the emulator uses always the same key and it’s also published in Books Online.

You can find it from the Start menu just typing "Azure Cosmos DB Emulator", once the emulator is running, there will be a small icon in the notification area of your task bar.04_first_steps_in_Cosmos_DB_emulator_notification

As mentioned earlier, the Data Explorer only allows you to query your database using the the SQL API, but if you've chosen for instance the Gremlin API, you will see your Edges and Vertices like documents instead of the visual representation like in the portal.

05_first_steps_in_Cosmos_DB_emulator_data_explorer

There are some limitations comparing to the Azure Portal, but it is good enough, specially if you can’t have access to the Portal. Some of the main differences between the service and the emulator are related to (no surprise) scalability and availability, also to the lack of consistency levels, maybe because it runs in our laptops and not in the cloud 😊.

For me, what I miss the most is the ability to use the Gremlin API like in the Azure Portal as the only API fully supported by the client is the SQL API, but you still can create graphs and query them using the Gremlin console.

Creating your Azure Cosmos DB Account

Creating a Cosmos DB account in the portal is as simple as any other resource, once you have logged in the Azure Portal, type Cosmos DB in the search box and select it to create your account.

02-Create_Cosmos_DB_Account_AZ_portal

Soon we need to start taking very important decisions and some of them will be perpetual, try to gather as much information as possible about the purpose of your Cosmos DB Account before jumping in to create one.

Each Cosmos DB Account can use one and only one API, we can choose from the following:

  • Core (SQL), this is the default choice and in case you don’t have any specific preference, the one to go.
  • Azure Cosmos DB for MongoDB API, to migrate existing MongoDB applications without having to rewrite them.
  • Cassandra, to migrate existing Cassandra applications transparently.
  • Azure Table, for applications written for Azure Table storage.
  • Gremlin (graph), to create graphs and query them using the open source driver Gremlin.Net.

If you are not migrating existing apps where the choice is more evident, you’d end up choosing between two options, the SQL API or the Gremlin API, which we will see in more depth in future posts.

02-Create_Cosmos_DB_Account-1

Recently Microsoft announced a free tier, which will take off our monthly bill the first 400 RU/s and 5GB of storage, so if we do not exceed those thresholds, we will not incur any expense.

As stated, the free/discount tier only applies to one account per subscription, but it’s still amazing you can have this for free.

If this is the first Cosmos DB account in your subscription (or none of the existing subscriptions is already using it), the option will available at the moment we are creating the account and cannot be enabled later.

Conclusion

In this post, I've showed you how you can get started with Cosmos DB, even if you don't have access to the Azure Portal.

I have in mind more posts to continue exploring Azure Cosmos DB and the different APIs, so stay tuned.

Thanks for reading.

Next episode - build your first database

Subscribe to Email Updates

Back to top