Skip to main content
Cloud / Azure / Products / Azure Cosmos DB - Azure Databases

Azure Cosmos DB - Azure Databases

Azure Cosmos DB: Globally distributed, multi-model NoSQL database for mission-critical applications

databases
Pricing Model Request Units (RU/s) or Serverless
Availability 60+ regions, multi-region writes
Data Sovereignty EU regions with data residency guarantees
Reliability 99.999% for multi-region, 99.99% single region SLA

Azure Cosmos DB is a fully managed NoSQL and relational database for modern app development with guaranteed single-digit millisecond response times and 99.999% availability. Supports multiple APIs including MongoDB, Cassandra, Gremlin, and native NoSQL.

What is Azure Cosmos DB?

Azure Cosmos DB is a fully managed, globally distributed NoSQL and relational database from Microsoft Azure for mission-critical applications. The service guarantees single-digit millisecond response times and up to 99.999% availability for multi-region deployments. Unlike traditional databases, Cosmos DB offers horizontal scaling across any number of Azure regions without requiring you to manage replication or sharding.

A key differentiator is multi-model support: you can access the same database through different APIs, including NoSQL (Document), MongoDB, Cassandra, Gremlin (Graph), and Table API. This means you can migrate existing MongoDB or Cassandra applications without code changes. Cosmos DB also offers five configurable consistency levels (Strong, Bounded Staleness, Session, Consistent Prefix, Eventual) that provide a middle ground between strict consistency and maximum performance. This allows you to choose the right balance between availability, latency, and consistency for each application.

For capacity planning, two models are available: Serverless is suitable for unpredictable workloads with sporadic traffic and bills per request. Provisioned Throughput (manual or with Autoscale) is designed for production workloads with constant or predictable traffic. Autoscale automatically adjusts Request Units (RU/s) to the load, optimizing costs during fluctuating utilization. Both models offer automatic indexing of all properties, Change Feed for event-driven architectures, and Point-in-Time Restore for up to 30 days.

Typical Use Cases

Globally Distributed E-Commerce Platforms

Online shops with worldwide customers use Cosmos DB for product catalogs, shopping carts, and order histories. Multi-region writes enable customers in Asia, Europe, and America to shop simultaneously while local replicas ensure low latencies. Session consistency guarantees that a customer sees their own changes immediately, even when global replication takes a few seconds.

IoT Telemetry and Time-Series Data

Millions of IoT devices continuously send sensor data to Cosmos DB. The serverless option is suitable for irregular data streams, while Autoscale optimizes costs for constant write loads. Change Feed enables stream processing via Azure Functions to detect anomalies in real-time. Automatic indexing of all properties allows ad-hoc queries without schema design.

Personalization and Recommendation Engines

Streaming services and content platforms store user profiles, watch history, and preferences in Cosmos DB. The Graph API (Gremlin) models relationships between users, content, and tags for collaborative filtering. With Session consistency, users see their interactions immediately, while Eventual consistency suffices for global recommendations. Sub-10ms latencies enable real-time personalization during browsing.

Gaming Leaderboards and Session Stores

Multiplayer games use Cosmos DB for real-time rankings, player stats, and matchmaking data. Low latency is crucial for gameplay features like live tournaments. Multi-region deployments reduce ping times for players worldwide. The Table API provides simple key-value access for session data, while NoSQL API supports complex player profiles.

Real-Time Analytics and Dashboards

Business intelligence applications aggregate data from various sources in Cosmos DB for live dashboards. Change Feed triggers Azure Functions that calculate metrics and visualize them in Power BI. Bounded Staleness consistency guarantees that analysts see data at most X seconds old. Autoscale automatically adapts to peak times, such as monthly reports.

Mobile Apps with Offline Sync

Mobile banking, CRM, and field service apps synchronize data between devices and cloud. The MongoDB API enables offline-first architectures with local databases on the device. Conflict resolution policies automatically resolve merge conflicts. Strong consistency for critical transactions combined with Eventual for non-critical data optimizes performance and compliance.

Multi-Region SaaS Platforms

B2B SaaS providers host multi-tenant applications in Cosmos DB with data residency per region. EU customers are stored exclusively in European regions, US customers in American regions. Partition keys by tenant ID logically isolate data. Provisioned Throughput with Reserved Capacity reduces costs for predictable SaaS workloads by up to 65%.

Azure Cosmos DB vs. Alternatives

When choosing a cloud solution, the question of alternatives often arises. Azure Cosmos DB competes with comparable services from other cloud providers:

  • AWS: DynamoDB
  • Google Cloud: Firestore

While functionality is often similar, services differ in pricing models, regional availability, and integration ecosystem. Azure particularly excels with enterprise customers using the Microsoft stack and hybrid cloud scenarios.

Best Practices for Azure Cosmos DB

Choose Consistency Levels Strategically

Do not use Strong Consistency by default. Session Consistency is sufficient for most applications and offers better latency in multi-region deployments. Strong only for financial transactions or inventory management. Eventual for analytics and reporting. Bounded Staleness as a middle ground when you need to define maximum staleness time (e.g., max 5 minutes old data).

Plan Partition Key Design from the Start

The partition key is the most important design decision and cannot be changed later. Choose a key with high cardinality (many unique values) and even request distribution. Avoid hot partitions through timestamps as keys. Example: For e-commerce, not productId (few bestsellers), but userId or composite key userId-date.

Decide Consciously Between Serverless and Provisioned

Serverless is suitable for dev/test environments, prototypes, and sporadic workloads under 50 GB. Production systems with constant traffic run cheaper with Provisioned. Autoscale is ideal for fluctuating but predictable workloads (e.g., business hours). Calculate the break-even: From approx. 100 RU/s continuous load, Provisioned is cheaper than Serverless.

Optimize Indexing Policies

Use custom indexing policies to optimize costs and performance. Exclude paths that are never queried (e.g., large binary data or internal IDs). Composite indexes accelerate multi-property queries. Spatial indexes only activate when using geo-queries. Each additional index increases write costs by 10-20%.

Improve Query Performance Through Design

Avoid cross-partition queries in hot paths. Denormalize data to eliminate joins. Use projections to load only needed properties. Implement continuation tokens for pagination instead of OFFSET. Change Feed instead of polling for change detection. Monitor RU consumption per query in Azure Portal.

Use Multi-Region Writes Selectively

Activate multi-region writes only when necessary, as it doubles costs and requires conflict resolution. For read-heavy workloads, single-write-region with read-only replicas suffices. Define explicit conflict resolution policies (Last-Write-Wins, Custom Merge, or Application-Level). Test conflict scenarios before production deployment.

Optimize Costs with Autoscale and Reserved Capacity

Use Autoscale instead of manual scaling to avoid idle times. Reserved Capacity offers up to 65% discount with 1-3 year commitment. Combine both: Reserved for baseline load, Autoscale for peaks. Monitor Normalized RU Consumption in the portal to detect over-provisioning. Delete old data with TTL instead of manual cleanup jobs.

Frequently Asked Questions about Azure Cosmos DB

Which consistency level should I choose?

For most applications, Session Consistency is optimal: it guarantees that a user immediately reads their own writes while other users experience eventual consistency. Strong Consistency is only needed for financial transactions, inventory systems, or auctions. Eventual is sufficient for analytics, caching, or social features. Bounded Staleness offers a middle ground with guaranteed maximum delay (e.g., max 10 seconds old).

How do I design the right partition key?

The partition key is the most important decision and cannot be changed later. Choose a property with high cardinality (many unique values) and even request distribution. Avoid status fields (few values) or timestamps (hot partitions). Good examples: userId, tenantId, deviceId. Bad examples: category, createdDate, status. For uneven distribution, use synthetic keys like userId-region.

What does Azure Cosmos DB really cost?

The pricing model is based on Request Units (RU/s), Storage (GB), and multi-region replication. A point read (1 KB) costs 1 RU, a write 5 RU. With Provisioned Throughput, you pay approx. €5.50/month per 100 RU/s. Serverless bills per million requests (approx. €0.25). Multi-region doubles costs. Reserved Capacity (1-3 years) saves up to 65%. Use the Azure Pricing Calculator for exact calculations based on your workload.

Is the MongoDB API fully compatible?

The MongoDB API supports Wire Protocol Version 4.0 and 4.2 with most features: CRUD operations, Aggregation Pipeline, Indexing, Transactions. Limitations: No server-side JavaScript, limited geo-queries, some aggregation operators missing. Migration tools like Azure Database Migration Service facilitate the move. Test your specific application before production migration, as edge cases may exist.

How does Change Feed work?

Change Feed is a persistent log of all changes in your container in chronological order. Every create and update operation is captured (deletes only with All Versions Mode). Use Azure Functions, Logic Apps, or custom consumers for event-driven architectures: real-time synchronization, materialized views, event sourcing, stream analytics. Change Feed stores changes for the TTL duration of your container.

Serverless or Provisioned Throughput?

Serverless is suitable for sporadic workloads, dev/test, prototypes, and apps with unpredictable traffic. Limitations: Max 50 GB storage, max 5,000 RU/s, cold-start latency. Provisioned (manual or Autoscale) is for production systems: unlimited storage, predictable costs, lower latency. Break-even is at approx. 100 RU/s continuous load. Autoscale combines flexibility with cost control and automatically adjusts RU/s between 10% and 100%.

What does multi-region replication cost?

Each additional read region doubles storage costs, throughput remains the same. Multi-region writes (active-active) doubles RU/s costs per region. Example: 1,000 RU/s in one region = €5.50. With 3 read regions: storage x3, RU/s same. With 3 write regions: storage x3, RU/s x3. Network egress between regions is additional (approx. €0.05/GB). For read-heavy workloads, read-only replicas suffice.

How do backup and point-in-time restore work?

Cosmos DB offers two backup modes: Periodic (every 4 hours, free, retention 8 hours to 30 days) and Continuous (PITR, paid, restore to any second of the last 30 days). Continuous Backup costs approx. 20% of storage costs additionally. Restore occurs to a new container, not in-place. Geo-redundant backups protect against region failure. Test restore procedures regularly.

Is Azure Cosmos DB GDPR compliant?

Yes, when you choose European Azure regions (West Europe, North Europe, Germany West Central). Microsoft provides Data Processing Addendum (DPA) and Standard Contractual Clauses (SCC). You control data residency through region selection. Encryption at rest and in transit is standard. Customer-Managed Keys (CMK) for additional control. Audit logs via Azure Monitor for compliance evidence. Ensure you do not activate multi-region replication outside the EU.

How does Cosmos DB integrate with other Azure services?

Native integration via Managed Identities eliminates secrets management. Azure Functions trigger on Change Feed. Logic Apps for no-code workflows. Synapse Link for analytics without ETL. Azure Search indexes Cosmos data. Event Grid for event-driven architectures. Azure Monitor for observability. Terraform and Bicep for Infrastructure as Code. SDKs for .NET, Java, Python, Node.js, Go.

Integration with innFactory

As a Microsoft Azure Partner, innFactory supports you in integrating and optimizing Azure Cosmos DB. We help with architecture, migration, operations, and cost optimization.

Contact us for a non-binding consultation on Azure Cosmos DB and Microsoft Azure.

Available Tiers & Options

Serverless

Strengths
  • Pay per request
  • Auto-scaling
  • No provisioning
Considerations
  • Higher per-request cost
  • Max 50GB storage
  • Cold start latency

Typical Use Cases

Real-time personalization and recommendations
IoT and time-series data
Globally distributed web and mobile apps
Retail and e-commerce catalogs
Gaming leaderboards and session stores

Technical Specifications

Apis NoSQL, MongoDB, Cassandra, Gremlin, Table, PostgreSQL
Backup Continuous backup and point-in-time restore (PITR)
Change feed Real-time change tracking for all operations
Consistency models Strong, Bounded Staleness, Session, Consistent Prefix, Eventual
Indexing Automatic indexing of all properties with customizable indexing policies
Latency <10ms read/write at P99
Modes Serverless or Provisioned (Manual/Autoscale)
Multi region Active-active multi-region writes with conflict resolution
Throughput Unlimited with partitioning

Frequently Asked Questions

What's the difference between Cosmos DB and DocumentDB?

Azure DocumentDB is now the MongoDB-compatible API for Cosmos DB. Cosmos DB is the evolution with multiple API support.

Can I migrate from MongoDB to Cosmos DB?

Yes, Cosmos DB offers native MongoDB API compatibility. Use Azure Database Migration Service for seamless migration.

Microsoft Solutions Partner

innFactory is a Microsoft Solutions Partner. We provide expert consulting, implementation, and managed services for Azure.

Microsoft Solutions Partner Microsoft Data & AI

Ready to start with Azure Cosmos DB - Azure Databases?

Our certified Azure experts help you with architecture, integration, and optimization.

Schedule Consultation