Understanding Azure Cosmos DB
This lesson explains semi-structured data, the Cosmos DB resource model and its APIs.
Learning outcomes
After completing this lesson, you will be able to:
- Identify when semi-structured storage is appropriate.
- Describe the Cosmos DB resource hierarchy.
- Choose an API.
- Compare Azure Table Storage with the Table API.
Semi-structured data
Semi-structured data has some organization, but no fixed schema. A JSON product record might contain the attributes that a particular product needs, and two products can have different fields. This flexibility lets applications evolve without schema migrations, and it fits data that is read as a whole, such as a customer profile or a shopping cart.
The choice of store depends on access patterns. If an application reads and writes individual items by key at high scale, a NoSQL database is suitable. If it needs complex joins across many entities with strong transactional guarantees, a relational database remains the better fit. Simple key and attribute data with modest needs may fit an inexpensive table store.
Relational, NoSQL or table store?
What Azure Cosmos DB provides
Azure Cosmos DB is a fully managed NoSQL database with low latency, automatic indexing and turnkey global distribution. Data can be replicated to any number of Azure regions by selecting them, and multi-region writes can be enabled. Microsoft offers an SLA of up to 99.999% availability for multi-region write accounts. Indexes are created automatically for all properties by default, and vector search features support AI applications.
The resource hierarchy is straightforward. An account is the top-level resource and defines the regions, the default consistency and the API. A database is a namespace for containers. A container holds items, and it is the unit of partitioning and throughput. An item is a document or row. Most design decisions are made at container level.
Choosing an API
Cosmos DB exposes several APIs, chosen when the account is created. An API determines the data model and wire protocol that applications use.
| API | Data model | Choose when |
|---|---|---|
| NoSQL | JSON documents with SQL-like queries | Building a new application; receives new features first |
| MongoDB | BSON documents | Migrating a MongoDB application with existing drivers |
| Apache Cassandra | Wide column | Migrating a Cassandra workload using CQL |
| Apache Gremlin | Graph | Traversing relationships such as social networks |
| Table | Key and attribute | Upgrading an Azure Table Storage application |
The selection rule is simple: new applications use the NoSQL API, and existing applications use the API that matches their current database, so that drivers and skills are preserved.
The following diagram compares two NoSQL stores for two different needs.

Which Cosmos DB API?
Related services
Three related services are easily confused with Cosmos DB accounts. Azure Table Storage is part of Azure Storage, offering an inexpensive key and attribute store with a single region of writes. The Cosmos DB Table API is wire-compatible, and offers global distribution and low latency at a higher cost. Azure DocumentDB is a separate service based on the vCore model, compatible with the MongoDB wire protocol and built on the PostgreSQL engine. It suits MongoDB workloads that prefer vCore-based pricing and has a 99.995% SLA.
The following comparison sets out the choice between Table Storage and the Cosmos DB Table API, a frequent exam distinction.
Table Storage or Cosmos DB?
Choosing a store
A gaming company is building a player profile service for players on three continents, each of whom expects response times under 20 milliseconds. Profiles vary by game and change often. Separately, an internal application stores 5 million simple device records, looked up by a device ID, and must be as cheap as possible. What should you recommend?
The profile service needs global, low-latency access to flexible documents, so Azure Cosmos DB for NoSQL suits it, with regions on each continent and multi-region writes if players should write to their nearest region.
The device records are simple, keyed lookups with no global requirement, and cost is the deciding qualifier, so Azure Table Storage is the recommendation. Using Cosmos DB for the device records would work but costs more than necessary, and Azure SQL Database would add a fixed schema and relational features that neither workload needs.
Which API should a new application use, and why?
Show answer
The NoSQL API. It is Cosmos DB's native API, and other APIs exist mainly to support migrations from their source databases.
Exam Tips
Remember for the exam
- New applications use the NoSQL API; migrations use the API matching the existing database.
- The container is the unit of partitioning and throughput.
- Table Storage is cheapest; the Cosmos DB Table API adds global reach and guaranteed throughput.
- Azure DocumentDB is a separate vCore service with MongoDB compatibility.