Introduction to Azure Cosmos DB: SQL API
The Azure Cosmos DB DocumentDB API or SQL (DocumentDB) API is now known as Azure Cosmos DB SQL API. You don't need to change anything to continue running your apps built with DocumentDB API. The functionality remains the same.
Azure Cosmos DB is Microsoft's globally distributed, multi-model database service for mission-critical applications. Azure Cosmos DB provides turn-key global distribution, elastic scaling of throughput and storage worldwide, single-digit millisecond latencies at the 99th percentile, five well-defined consistency levels, and guaranteed high availability, all backed by industry-leading SLAs. Azure Cosmos DB automatically indexes data without requiring you to deal with schema and index management. It is multi-model and supports document, key-value, graph, and columnar data models.
With the SQL API, Azure Cosmos DB provides rich and familiar SQL query capabilities with consistent low latencies over schema-less JSON data. In this article, we provide an overview of the Azure Cosmos DB's SQL API, and how you can use it to store massive volumes of JSON data, query them within order of milliseconds latency, and evolve the schema easily.
What capabilities and key features does Azure Cosmos DB offer?
Azure Cosmos DB, via the SQL API, offers the following key capabilities and benefits:
Elastically scalable throughput and storage: Easily scale up or scale down your JSON database to meet your application needs. Your data is stored on solid-state disks (SSD) for low predictable latencies. Azure Cosmos DB supports containers for storing JSON data called collections that can scale to virtually unlimited storage sizes and provisioned throughput. You can elastically scale Azure Cosmos DB with predictable performance seamlessly as your application grows.
Multi-region replication: Azure Cosmos DB transparently replicates your data to all regions you've associated with your Azure Cosmos DB account, enabling you to develop applications that require global access to data while providing tradeoffs between consistency, availability, and performance, all with corresponding guarantees. Azure Cosmos DB provides transparent regional failover with multi-homing APIs, and the ability to elastically scale throughput and storage across the globe. Learn more in Distribute data globally with Azure Cosmos DB.
Ad hoc queries with familiar SQL syntax: Store heterogeneous JSON documents and query these documents through a familiar SQL syntax. Azure Cosmos DB utilizes a highly concurrent, lock free, log structured indexing technology to automatically index all document content. This enables rich real-time queries without the need to specify schema hints, secondary indexes, or views. Learn more in Query Azure Cosmos DB.
Tunable consistency levels: Select from five well-defined consistency levels to achieve optimal trade-off between consistency and performance. For queries and read operations, Azure Cosmos DB offers five distinct consistency levels: strong, bounded-staleness, session, consistent prefix, and eventual. These granular, well-defined consistency levels allow you to make sound trade-offs between consistency, availability, and latency. Learn more in Using consistency levels to maximize availability and performance.
Fully managed: Eliminate the need to manage database and machine resources. As a fully managed Microsoft Azure service, you do not need to manage virtual machines, deploy and configure software, manage scaling, or deal with complex data-tier upgrades. Every database is automatically backed up and protected against regional failures. You can easily add an Azure Cosmos DB account and provision capacity as you need it, allowing you to focus on your application instead of operating and managing your database.
Automatic indexing: By default, Azure Cosmos DB automatically indexes all the documents in the database and does not expect or require any schema or creation of secondary indices. Don't want to index everything? Don't worry, you can opt out of paths in your JSON files too.
Change feed support: Change feed provides a sorted list of documents within an Azure Cosmos DB collection in the order in which they were modified. This feed can be used to listen for modifications to data in order to replicate data, trigger API calls, or perform stream processing on updates. Change feed is automatically enabled and easy to use: learn more about change feed.
How do you manage data with the SQL API?
The SQL API helps manage JSON data through well-defined database resources. These resources are replicated for high availability and are uniquely addressable by their logical URI. The SQL API offers a simple HTTP-based RESTful programming model for all resources.
The Azure Cosmos DB database account is a unique namespace that gives you access to Azure Cosmos DB. Before you can create a database account, you must have an Azure subscription, which gives you access to a variety of Azure services.
All resources within Azure Cosmos DB are modeled and stored as JSON documents. Resources are managed as items, which are JSON documents containing metadata, and as feeds that are collections of items. Sets of items are contained within their respective feeds.
The image below shows the relationships between the Azure Cosmos DB resources:
A database account consists of a set of databases, each containing multiple collections, each of which can contain stored procedures, triggers, UDFs, documents, and related attachments. A database also has associated users, each with a set of permissions to access various other collections, stored procedures, triggers, UDFs, documents, or attachments. While databases, users, permissions, and collections are system-defined resources with well-known schemas - documents, stored procedures, triggers, UDFs, and attachments contain arbitrary, user-defined JSON content.
How can I develop apps with the SQL API?
Azure Cosmos DB exposes resources through the REST APIs that can be called by any language capable of making HTTP/HTTPS requests. Additionally, we offer programming libraries for several popular languages for the SQL API. The client libraries simplify many aspects of working with the API by handling details such as address caching, exception management, automatic retries, and so forth. Libraries are currently available for the following languages and platforms:
|.NET SDK||.NET library|
|Node.js SDK||Node.js library|
|Java SDK||Java library|
|Python SDK||Python library|
|n/a||API for MongoDB|
Using the Azure Cosmos DB Emulator, you can develop and test your application locally with the SQL API, without creating an Azure subscription or incurring any costs. When you're satisfied with how your application is working in the emulator, you can switch to using an Azure Cosmos DB account in the cloud.
For .NET developers, the SQL API .NET SDK also offers a LINQ query provider.
Already have an Azure account? Then you can get started with Azure Cosmos DB by following our quick starts, which will walk you through creating an account and getting started with Cosmos DB.