Cosmos DB API Selection Guide

Watch the video to deepen your understanding.
SubscribeComplete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Cosmos DB API Selection Guide
Introduction
Azure Cosmos DB is a globally distributed, multi-model database service. Unlike traditional databases that force you into a single data model, Cosmos DB offers multiple APIs to interact with your data. This "multi-model" capability is one of its greatest strengths—and its greatest point of confusion for architects.
Choosing the right API is the most critical decision in your design phase. Once you commit to an API, migrating your data model to a different one later can be expensive and complex. This guide will help you navigate these options based on your application's data structure, query patterns, and existing ecosystem.
Understanding the API Options
Cosmos DB supports five primary APIs. Each is designed to handle specific data structures and developer workflows:
1. Core (SQL) API
The Core API is the native interface for Cosmos DB. It uses JSON as the storage format and SQL-like syntax for querying.
- Best for: General-purpose applications, microservices, and scenarios requiring high-performance document storage.
- Example: Storing user profiles, e-commerce product catalogs, or IoT sensor telemetry.
2. MongoDB API
This API provides wire-protocol compatibility with MongoDB. If you have an existing MongoDB application, you can migrate to Cosmos DB with minimal code changes.
- Best for: Migrating existing MongoDB workloads or teams already familiar with the MongoDB driver ecosystem.
3. Cassandra API
This API provides compatibility with Apache Cassandra. It is designed for wide-column stores.
- Best for: Time-series data, heavy write-throughput applications, and scenarios where you are already using Cassandra.
4. Gremlin (Graph) API
Designed for highly connected data, this API uses Apache TinkerPop to traverse relationships.
- Best for: Social networks, recommendation engines, and fraud detection systems where the relationship between entities is as important as the entities themselves.
5. Table API
A key-value store designed for simple, fast lookups.
- Best for: Simple data structures that do not require complex indexing or querying. It is the most cost-effective option for basic storage.
Practical Examples & Code Snippets
Scenario: Storing User Metadata (Core SQL API)
If you are building a modern web application, the Core API is usually the standard choice due to its rich indexing capabilities.
// Example: Creating a document in Core (SQL) API using Node.js SDK
const { CosmosClient } = require("@azure/cosmos");
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "UserDB" });
const { container } = await database.containers.createIfNotExists({ id: "Profiles" });
const newUser = {
id: "user_123",
name: "Jane Doe",
email: "jane@example.com",
preferences: { theme: "dark", notifications: true }
};
await container.items.create(newUser);
Scenario: Social Network Relationships (Gremlin API)
If you need to find "friends of friends," a graph structure is superior to a document structure.
// Example: Gremlin query to find friends of a user
g.V().has('user', 'name', 'Jane').out('follows').out('follows').dedup()
Best Practices for API Selection
- Prioritize the Core (SQL) API: Unless you have a strict requirement for legacy compatibility (like existing Mongo drivers or Cassandra expertise), start with the Core API. It offers the most features, the best integration with Azure services (like Azure Functions and Synapse Link), and the best performance tuning options.
- Evaluate Query Patterns First: Don't choose an API based on what you know; choose based on how you need to query. If your data is highly relational, don't force it into the Table API.
- Use the Right Tool for Scaling: If you have massive write-heavy workloads, the Cassandra API excels at write-throughput. If you have complex, read-heavy analytical needs, the Core API's indexing policies are more robust.
- Leverage Azure Synapse Link: If you choose the Core (SQL) API or MongoDB API, you can enable Synapse Link to perform near real-time analytics on your data without impacting transactional performance.
Common Pitfalls
- "The Migrator's Trap": Choosing an API just because you have existing code, even if that code's data model is a poor fit for the long-term requirements of the application. Always evaluate if a refactor to the Core API is worth the effort for better performance and feature access.
- Ignoring Partition Keys: Regardless of the API chosen, the Partition Key is the most important design element. Choosing a poor partition key will lead to "hot partitions," causing performance bottlenecks that no API change can fix.
- Over-indexing: While the Core API allows for powerful indexing, indexing every field increases your Request Unit (RU) consumption on every write. Only index the fields you actually query.
💡 Pro Tip: When in doubt, prototype.
Cosmos DB allows you to create multiple containers under the same account. You can prototype a small subset of your data in both the Core API and the API you are considering to compare the performance and the developer experience of the SDKs.
Key Takeaways
- Multi-Model Flexibility: Cosmos DB allows you to pick the API that fits your data model, not the other way around.
- Core API is the Default: For new greenfield projects, the Core (SQL) API is almost always the recommended path due to its maturity and feature set.
- Compatibility APIs: Use MongoDB, Cassandra, Gremlin, or Table APIs primarily for migrating existing applications or when team expertise is heavily tied to those specific ecosystems.
- Design for Scale: Regardless of the API, your success depends on choosing an effective Partition Key and optimizing your indexing policy.
- Future-Proofing: Consider how your data needs will evolve. If your data structure might become highly complex or deeply connected, choose an API that can handle that evolution gracefully.
Reach the last section to complete this lesson and earn points — you're on section 1 of 4.
- Introduction to Azure Monitor
- Azure Monitor Architecture and Data Sources
- Configuring Log Analytics Workspaces
- Designing Log Routing Solutions
- Configuring Diagnostic Settings
- Application Insights for Solution Architects
- Network Watcher and Network Monitoring
- Azure Monitor Alerts and Action Groups
- Workbooks and Custom Dashboards
- Designing a Comprehensive Monitoring Strategy
- Logging and Monitoring Quiz5q
- Microsoft Entra ID for Solution Architects
- Designing Identity Solutions: B2B Collaboration
- Designing Identity Solutions: B2C Scenarios
- Conditional Access Policy Design
- Designing for Multi-Factor Authentication
- Managed Identities for Azure Resources
- Service Principals and App Registrations
- Role-Based Access Control Design
- Privileged Identity Management
- Microsoft Entra ID Protection
- Zero Trust Architecture with Microsoft Entra
- Authentication and Authorization Quiz5q
- Introduction to Azure Governance
- Designing Management Group Hierarchies
- Subscription Strategy Design
- Resource Group Organization Patterns
- Azure Policy Design and Assignment
- Custom Policy Definitions and Initiatives
- Resource Locks and Tagging Strategies
- Azure Blueprints and Landing Zones
- Cost Management and Budget Design
- Cloud Adoption Framework for Governance
- Governance Solutions Quiz5q
- Introduction to Azure Storage
- Storage Account Types and Replication
- Blob Storage Tiers and Lifecycle Management
- Azure Files and Azure NetApp Files
- Azure Managed Disks Design
- Azure Data Lake Storage Gen2
- Cosmos DB Consistency Models
- Cosmos DB Partitioning and Throughput Design
- Cosmos DB API Selection Guide
- Table Storage and Queue Storage Design
- Storage Security and Encryption
- Non-Relational Storage Quiz5q
- Azure SQL Database Service Tiers
- Azure SQL Managed Instance Design
- Azure Database for MySQL and PostgreSQL
- Database Scaling: Vertical and Horizontal
- Read Replicas and Geo-Replication
- Database Security and Auditing Design
- Transparent Data Encryption and Always Encrypted
- Caching with Azure Cache for Redis
- Azure SQL Elastic Pools Design
- Relational Storage Quiz5q
- Azure Data Factory Design Patterns
- Data Integration Pipeline Architecture
- Azure Synapse Analytics Design
- Azure Databricks Integration Patterns
- Azure Stream Analytics for Real-Time Data
- Azure Event Hubs for Data Ingestion
- Data Migration Strategies and Tools
- Azure Purview for Data Governance
- Data Integration Quiz5q
- Introduction to High Availability in Azure
- Availability Zones and Availability Sets
- Azure Load Balancer Design
- Application Gateway and WAF Design
- Azure Front Door and Global Load Balancing
- Azure Traffic Manager Routing Methods
- Multi-Region Architecture Design
- SLA Design and Composite SLAs
- Health Probes and Failover Configuration
- Azure Service Fabric for Stateful HA
- High Availability Quiz5q
- Azure Backup Architecture and Vaults
- Backup Policies for VMs and Databases
- Azure Site Recovery Design
- RTO and RPO Planning Strategies
- Geo-Redundant and Cross-Region Recovery
- Hybrid and On-Premises Backup Solutions
- Resiliency Patterns and Chaos Engineering
- Disaster Recovery Testing and Drills
- Azure Immutable Backup and Soft Delete
- Backup and Disaster Recovery Quiz5q
- Introduction to Azure Compute Options
- Virtual Machine Design and Sizing
- VM Scale Sets and Autoscaling Strategies
- Azure Batch for Large-Scale Workloads
- Azure App Service Plans and Design
- App Service Environments and Isolation
- Azure Container Instances
- Azure Kubernetes Service Architecture
- AKS Networking and Storage Design
- Azure Functions and Serverless Design
- Durable Functions and Orchestration
- Compute Decision Framework
- Azure Virtual Desktop Design
- Compute Solutions Quiz5q
- Microservices Architecture Patterns
- Azure API Management Design
- Azure Service Bus Messaging Design
- Azure Event Grid and Event-Driven Architecture
- Azure Event Hubs for Streaming
- Azure Logic Apps and Integration Workflows
- Azure SignalR and Web PubSub
- Caching Strategies and Azure CDN
- App Configuration and Feature Flags
- Designing for Scalability and Performance
- Azure Container Apps Design
- Application Architecture Quiz5q
- Virtual Network Design and Address Planning
- Subnet Design and Network Segmentation
- Hub-Spoke Network Topology
- Azure Virtual WAN Design
- VPN Gateway Design and Configuration
- ExpressRoute Circuit Design
- Network Security Groups Design
- Azure Firewall and Firewall Manager
- Azure DDoS Protection Design
- Private Endpoints and Private Link
- Azure DNS and DNS Architecture
- Network Performance and Traffic Routing
- Azure Bastion and Secure Access
- Network Solutions Quiz5q
- Azure Migrate Overview and Assessment
- Migration Assessment and Discovery
- Azure Cloud Adoption Framework for Migration
- VM Migration with Azure Migrate
- Database Migration with Azure DMS
- Application Migration to App Service
- Containerizing Applications for Migration
- Migration Cost Planning and Optimization
- Data Box and Offline Migration Methods
- Migrations Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons