Azure Cosmos DB API for NoSQL – Complete Guide for DP-900
Why Is Azure Cosmos DB API for NoSQL Important?
Azure Cosmos DB is Microsoft's flagship globally distributed, multi-model database service. Among its several APIs, the API for NoSQL (formerly known as the SQL API or Core API) is the native and most feature-rich interface for working with Cosmos DB. Understanding this API is critical for the DP-900 exam because it represents the primary way Microsoft envisions developers interacting with non-relational data in Azure. It combines the flexibility of a document database with a familiar SQL-like query language, making it a central topic in the "Describe non-relational data on Azure" section of the exam.
What Is Azure Cosmos DB API for NoSQL?
The API for NoSQL is the default and recommended API when creating an Azure Cosmos DB account. Key characteristics include:
• Document Store: Data is stored as JSON documents. Each document can have a different structure (schema-free), providing great flexibility.
• SQL-Like Query Language: Despite being a NoSQL database, you query data using a SQL-like syntax. For example: SELECT c.name, c.email FROM c WHERE c.city = 'Seattle'. This makes adoption easier for developers already familiar with SQL.
• Native Cosmos DB API: It is the core (native) API of Cosmos DB, meaning it always gets the latest features and optimizations first. Other APIs (MongoDB, Cassandra, Gremlin, Table) are compatibility layers built on top of the same engine.
• JSON Documents: Every item stored is a JSON document. Documents are organized into containers (analogous to tables), and containers are grouped into databases.
• SDK Support: Microsoft provides SDKs for .NET, Java, Python, Node.js, and other languages to interact with this API programmatically.
How Does It Work?
Understanding the architecture and key concepts is essential:
1. Hierarchy of Resources
• Account → The top-level resource. You choose the API (NoSQL) at account creation time.
• Database → A logical namespace for containers.
• Container → Where JSON documents (items) are stored. A container is the unit of scalability.
• Items → Individual JSON documents within a container.
2. Partition Key
When you create a container, you must specify a partition key. This is a property in your JSON documents (e.g., /city or /customerId) that Cosmos DB uses to distribute data across physical partitions. A well-chosen partition key ensures even data distribution and efficient queries.
3. Request Units (RUs)
Cosmos DB measures throughput in Request Units per second (RU/s). Every operation (read, write, query) consumes a certain number of RUs. You provision throughput at the container or database level. There are two throughput modes:
• Provisioned Throughput: You set a fixed number of RU/s (can be manual or autoscale).
• Serverless: You pay only for the RUs consumed per operation—ideal for intermittent or unpredictable workloads.
4. Global Distribution
Cosmos DB allows you to replicate your data across multiple Azure regions with a single click. The API for NoSQL fully supports:
• Multi-region reads: Low-latency reads from the nearest replica.
• Multi-region writes: Write to any region (multi-master).
• Automatic failover: High availability with 99.999% SLA for multi-region accounts.
5. Consistency Levels
Cosmos DB offers five consistency levels (from strongest to weakest):
• Strong – Reads always return the most recent committed write.
• Bounded Staleness – Reads lag behind writes by at most a configured time or number of operations.
• Session – Default level. Within a single session, reads are consistent with that session's writes.
• Consistent Prefix – Reads never see out-of-order writes.
• Eventual – No ordering guarantee; highest performance and lowest latency.
6. Indexing
By default, Cosmos DB automatically indexes every property in every JSON document. You do not need to define indexes upfront. You can customize the indexing policy if you want to include/exclude specific paths to optimize RU consumption.
7. Querying
The SQL-like query syntax supports:
• SELECT, FROM, WHERE, ORDER BY, JOIN (within a document)
• Built-in functions for strings, arrays, math, and spatial data
• Aggregates like COUNT, SUM, AVG, MIN, MAX
When to Use the API for NoSQL
• You are building a new application and want the richest Cosmos DB feature set.
• Your data is naturally represented as JSON documents.
• You want a SQL-like query experience over non-relational data.
• You do not need wire-protocol compatibility with MongoDB, Cassandra, Gremlin, or Azure Table Storage.
• You need global distribution, low latency, and high availability.
Comparison with Other Cosmos DB APIs
• API for MongoDB: Choose if you have existing MongoDB applications and want to migrate without code changes.
• API for Apache Cassandra: Choose for wide-column workloads with existing Cassandra expertise.
• API for Apache Gremlin: Choose for graph data (nodes and edges, relationships).
• API for Table: Choose if migrating from Azure Table Storage and want premium features.
• API for NoSQL: Choose for new projects, richest features, SQL-like queries on JSON documents.
Exam Tips: Answering Questions on Azure Cosmos DB API for NoSQLHere are key strategies and facts to remember for the DP-900 exam:
✅
Tip 1 – Know It Is the Default/Native API: If a question describes a scenario involving a new Cosmos DB application with JSON documents and SQL-like queries, the answer is almost always the API for NoSQL. It is the recommended starting point for new projects.
✅
Tip 2 – SQL-Like Does NOT Mean Relational: Do not confuse the SQL-like query syntax with a relational database. Cosmos DB API for NoSQL stores schema-free JSON documents. The SQL syntax is just the query language; the underlying data model is non-relational.
✅
Tip 3 – Remember the Resource Hierarchy: Account → Database → Container → Item. Questions may test whether you know what a
container is (the scalability unit) or what an
item is (a single JSON document).
✅
Tip 4 – Partition Key Is Chosen at Creation: You must select a partition key when creating a container, and it
cannot be changed later. Questions may test your understanding that the partition key determines data distribution.
✅
Tip 5 – Request Units (RUs) Are the Currency: All operations cost RUs. If a question asks about how throughput is measured or billed in Cosmos DB, the answer is Request Units per second (RU/s).
✅
Tip 6 – Default Consistency Is Session: If asked about the default consistency level, the answer is
Session. Know the five levels and their order from strongest (Strong) to weakest (Eventual).
✅
Tip 7 – Automatic Indexing: Cosmos DB indexes all properties by default. If a question asks whether you need to create indexes manually, the answer is no (unless you want a custom indexing policy).
✅
Tip 8 – Global Distribution Scenarios: If a scenario mentions users in multiple regions needing low-latency access, think Cosmos DB with multi-region replication. The API for NoSQL supports both multi-region reads and multi-region writes.
✅
Tip 9 – Distinguish from Other APIs: If the question mentions graph traversal → Gremlin. If it mentions existing MongoDB workloads → MongoDB API. If it mentions wide-column or CQL → Cassandra API. If it mentions new project with JSON and SQL-like queries → API for NoSQL.
✅
Tip 10 – Watch for Keyword Clues: Look for keywords in exam questions such as
"JSON documents," "SQL-like queries," "globally distributed," "schema-free," "low latency," and
"multi-model." These strongly point toward Cosmos DB API for NoSQL.
✅
Tip 11 – SLA Knowledge: Cosmos DB offers industry-leading SLAs—up to
99.999% availability for multi-region configurations. This may appear in questions about high availability.
✅
Tip 12 – Serverless vs. Provisioned: Know that serverless mode is best for development, testing, or sporadic workloads, while provisioned throughput (manual or autoscale) is better for production workloads with predictable traffic.
SummaryThe Azure Cosmos DB API for NoSQL is Microsoft's native, feature-rich API for working with JSON document data in a globally distributed, highly available, and low-latency database. For the DP-900 exam, focus on understanding its role as the default API, the resource hierarchy, partition keys, Request Units, consistency levels, and how to differentiate it from the other Cosmos DB APIs. Master these concepts and the exam tips above, and you will be well-prepared to answer any related questions confidently.