Brains4Cloud
ESEN
Practice

Topic 4 of 4

D3 · Non-relational data on Azure

Azure Cosmos DB APIs

Cosmos DB doesn't lock you into a single data model or query language. It offers several APIs compatible with tools developers already know. The exam gives a scenario (an app on MongoDB, a graph, a key-value table) and asks for the right API.

When you create a Cosmos DB account, you choose the API. That choice determines how the application interacts: what format it sends, what query language it uses, and which client libraries it works with. Internally, Cosmos DB stores data in its own format; the API is an abstraction layer on top.

The benefit: portability

If a team already has an application on MongoDB or Apache Cassandra, it can point it at Cosmos DB with minimal changes and gain global distribution, managed throughput, and SLA-backed availability.

The five supported APIs are NoSQL, MongoDB, Table, Apache Cassandra, and Apache Gremlin. Azure Cosmos DB for PostgreSQL is a separate offering on a retirement path, not recommended for new projects.

API for NoSQL

It's Cosmos DB's native API. It stores data as JSON documents and lets you query it with SQL-like syntax. It was previously called the SQL API: if older documentation says "SQL API", it's the same service.

SELECT *
FROM customers c
WHERE c.id = "joe@litware.com"

-- Result: a JSON document
{
  "id": "joe@litware.com",
  "name": "Joe Jones",
  "address": { "street": "1 Main St.", "city": "Seattle" }
}
  • Microsoft recommends it for high-scale scenarios that need a 99.999% SLA, instant autoscale, and automatic failover across regions.
  • It supports Fabric mirroring: it replicates operational data into Microsoft Fabric with no ETL pipeline, to analyze it in near real time without consuming RUs or affecting the transactional workload.

API for MongoDB

Compatible with MongoDB drivers and client libraries, so existing applications connect without significant changes. Data is stored in BSON (binary JSON) and queried with MQL (MongoDB Query Language), an object-oriented syntax where you call methods on collections.

db.products.find({id: 123})

-- Result
{ "id": 123, "name": "Hammer", "price": 2.99 }

An important nuance

It fits when the team knows MongoDB and wants to use its drivers with Cosmos DB's global model. To migrate an existing MongoDB application or use the full MQL, Microsoft recommends Azure DocumentDB, a separate service with MongoDB wire protocol compatibility.

API for Table

It stores key-value pairs in tables with the same programming model as Azure Table Storage. A Table Storage app connects with minimal changes and gains scalability, global distribution, and automatic indexing on every property.

PartitionKeyRowKeyNameEmail
1123Joe Jonesjoe@litware.com
1124Samir Nadoysamir@northwind.com

Each row is identified by PartitionKey + RowKey and retrieved through a REST-style endpoint, for example Customers(PartitionKey='1',RowKey='124').

API for Apache Cassandra

Compatible with Apache Cassandra, an open-source database with a column-family storage model: rows don't have to contain the same columns, unlike a relational table.

SELECT * FROM Employees WHERE ID = 2

It uses CQL (Cassandra Query Language), with SQL-like syntax. It fits when migrating a Cassandra workload to a managed cloud database.

API for Apache Gremlin

Designed for graph data: entities are vertices (nodes) and relationships are edges. Useful when the connections matter as much as the data: social networks, recommendation engines, fraud detection, and organizational hierarchies.

g.addV('employee').property('id', '3').property('firstName', 'Alice')
g.V('3').addE('reports to').to(g.V('1'))

g.V().hasLabel('employee').order().by('id')

Gremlin is the language for traversing and manipulating the graph: the example adds an employee, connects her to her manager, and then lists employees in order.

How to choose the API

APIData modelLanguageChoose it if…
NoSQLJSON documentsSQL-like syntaxA new app, maximum scale
MongoDBBSON documentsMQLThe team uses MongoDB
TableKey-valueTable Storage APIYou're coming from Azure Table Storage
CassandraColumn familyCQLYou're coming from Apache Cassandra
GremlinGraphGremlinThe relationships are what matters

Exam scenarios

SituationAPIWhy
A new app with JSON documents and SQL-like query syntaxAPI for NoSQLThe native Cosmos DB API.
Analyze operational data in near real time without building ETLAPI for NoSQL with Fabric mirroringReplicates to Fabric without consuming RUs.
An existing application using MongoDB driversAPI for MongoDBCompatible with MongoDB drivers and libraries.
Migrate an Azure Table Storage app while gaining global distributionAPI for TableThe same programming model.
Migrate an Apache Cassandra workload to a managed serviceAPI for Apache CassandraColumn families and CQL.
Detect fraud by traversing relationships between accountsAPI for Apache GremlinGraphs with vertices and edges.
Migrate MongoDB using the full MongoDB Query LanguageAzure DocumentDBMicrosoft's recommended option for that case.

Common exam traps

❓ Is Cosmos DB's "SQL API" a different API from NoSQL?

No. It's the former name of the API for NoSQL.

❓ Does the API for NoSQL turn Cosmos DB into a relational database?

No. It stores JSON documents; only the query syntax resembles SQL.

❓ What format does the API for MongoDB store data in?

BSON (binary JSON), queried with MQL.

❓ Which language does the API for Apache Cassandra use?

CQL (Cassandra Query Language).

❓ What are entities and relationships called in Gremlin?

Vertices (nodes) and edges.

❓ How many APIs does Cosmos DB support?

Five: NoSQL, MongoDB, Table, Apache Cassandra, and Apache Gremlin.

❓ Is the API chosen per container?

No. It's chosen when you create the Cosmos DB account.

Did you get this topic?

Test what you just learned

A social network wants to store users and who follows whom, and quickly query a person's friends of friends. Which Cosmos DB API should it use?

Ready to test "Azure Cosmos DB APIs"?

Original questions, each with a full explanation.

Start a mock exam