Azure Cosmos DB: The Global Distribution, Multi-Model Database Service
Azure Cosmos DB is a globally distributed, multi-model database service that enables you to harness the benefits of geo-distribution by allowing you to read and write data in any Azure region, anywhere in the world, with guaranteed low latency, high availability, and elastic scalability.
Cosmos DB is a proprietary database engine from Microsoft. It's designed for mission-critical applications, offering enterprise-grade security, comprehensive SLAs, and industry-leading R&D investments.
Getting Started
Begin your journey with Azure Cosmos DB by following these quick steps:
-
Create an Azure Cosmos DB account:
You can create an account using the Azure portal, Azure CLI, or programmatically.
Azure CLI Example
az cosmosdb create \ --name mycosmosdbaccount \ --resource-group myResourceGroup \ --kind GlobalDocumentDB -
Create a database and container:
Define your data structure by creating databases and containers (collections, tables, or graphs).
-
Connect and interact:
Use one of the many SDKs or APIs to start adding and querying your data.
Core Concepts
Understanding these fundamental concepts is key to effectively using Azure Cosmos DB.
Table of Contents
Databases
A database is a logical namespace that hosts a set of containers. It acts as a unit of management for billing and provisioning.
Containers
A container is the schema-agnostic, hierarchical collection of items. You provision throughput (Request Units per second - RU/s) and storage on a container. Containers can span across multiple partitions.
Items
Items are the fundamental units of data stored and manipulated in Cosmos DB. In the SQL (Core) API, an item is a JSON document. Other APIs support different item types (e.g., BSON documents for MongoDB API, rows for Table API).
Partitioning
Partitioning is the mechanism by which Cosmos DB distributes data and throughput across multiple logical and physical partitions. A partition key is a property within your items that Cosmos DB uses to determine which partition the item belongs to. Proper partition key selection is crucial for performance and scalability.
Indexing
Cosmos DB automatically indexes all data stored in a container without requiring schema or secondary indexes. The indexing policy controls which paths are indexed and how. The default indexing policy is generally optimal for most scenarios.
Consistency Models
Cosmos DB offers five well-defined consistency levels, providing a trade-off between consistency, availability, and latency:
- Strong
- Bounded Staleness
- Session
- Consistent Prefix
- Eventual
You can choose the consistency level that best suits your application's needs.
APIs
Cosmos DB supports multiple data models and APIs, allowing you to use your existing development skills and familiar frameworks.
SQL (Core) API
The native API for Cosmos DB, offering rich querying capabilities using a familiar SQL syntax for JSON documents.
MongoDB API
Compatibility with MongoDB, allowing you to migrate existing MongoDB applications to Azure with minimal code changes.
Cassandra API
Compatibility with Apache Cassandra, enabling you to leverage Cosmos DB's global distribution and scalability for Cassandra workloads.
Gremlin API
Support for Apache TinkerPop Gremlin, ideal for graph database workloads and representing complex relationships.
Table API
Compatibility with Azure Table storage, providing a key-value and document data model.
SDK & Tools
Access and manage your Cosmos DB data with a variety of SDKs and tools.
.NET SDK
Comprehensive SDK for .NET developers, supporting asynchronous operations and a rich set of features.
Java SDK
Robust SDK for Java applications, integrating seamlessly with the Java ecosystem.
Node.js SDK
Asynchronous SDK for Node.js, enabling efficient data access in JavaScript applications.
Python SDK
Python SDK for interacting with Cosmos DB, offering intuitive APIs for data manipulation.
Azure CLI
Manage your Cosmos DB resources from the command line.
REST API
Direct interaction with Cosmos DB via its comprehensive RESTful API.
Tutorials
Explore our step-by-step tutorials to learn how to implement common scenarios with Azure Cosmos DB, such as:
- Creating a web application with Cosmos DB
- Implementing change feed processing
- Migrating data to Cosmos DB
- Optimizing performance and cost
Code Samples
Find practical code samples for various languages and scenarios on our GitHub repository.
Pricing
Understand the pricing model for Azure Cosmos DB, which is based on provisioned throughput (RU/s) and consumed storage. Learn about free tier options and cost optimization strategies.
Support & Community
Get help and connect with the Azure Cosmos DB community: