Why Cosmos DB Matters
Modern applications often need to handle global scale, millions of requests per second, and low latency — something traditional relational databases can’t easily deliver.
Azure Cosmos DB is Microsoft’s fully managed NoSQL database service, designed for globally distributed, high-performance workloads.
As a Solution Architect, your role is to identify when Cosmos DB is the right fit, and how to design it using the correct consistency, partitioning, and API choices.
Core Features of Cosmos DB
1. Multi-Model APIs
-
Core (SQL API) – default document store.
-
MongoDB API – for MongoDB apps.
-
Cassandra API – for wide-column workloads.
-
Gremlin API – for graph databases.
-
Table API – for key-value storage (more advanced than Azure Table Storage).
2. Global Distribution
-
Write and read data from multiple regions.
-
Replication with multi-master support (active-active).
3. Consistency Levels
Cosmos DB provides five consistency models:
-
Strong – strict consistency (slower, expensive).
-
Bounded Staleness – lag within time/ops.
-
Session – consistency per user session (default).
-
Consistent Prefix – order preserved, eventual consistency.
-
Eventual – fastest, least consistent.
4. Partitioning
-
Data is distributed using partition keys for scalability.
-
Choosing a poor partition key leads to hotspots and poor performance.
5. Throughput (RUs)
-
Cosmos DB uses Request Units (RUs) to measure performance.
-
Scale up/down based on workload.
-
Autoscale option available.
Design Patterns & Use Cases
Pattern 1: Globally Distributed Applications
-
E.g., A social media app with users across continents.
-
Use multi-region write to keep latency low.
Pattern 2: IoT & Telemetry
-
Billions of device messages stored as JSON docs.
-
Use partitioning on device ID.
Pattern 3: Personalization & Recommendation Engines
-
Store user behavior events for real-time personalization.
Pattern 4: Multi-Model Data Needs
-
Use Graph API for relationships (friends/followers).
-
Use SQL API for product catalog.
Example Enterprise Scenario
A gaming company wants:
-
A global database that supports millions of concurrent players.
-
Low latency regardless of player’s location.
-
Session-level consistency for each user.
Correct design:
-
Deploy Cosmos DB with multi-region write.
-
Use Session consistency.
-
Partition data by PlayerID for even distribution.
Confusion Buster
-
Cosmos DB vs SQL Database: Cosmos = NoSQL, schema-less, global scale. SQL = relational, structured, transactional.
-
Cosmos DB vs Table Storage: Cosmos = premium NoSQL with global distribution + rich APIs. Table = basic key-value, cheap.
-
Cosmos DB vs MongoDB: Cosmos offers MongoDB API compatibility but adds Azure features like multi-region and consistency choices.
Exam Tips
-
“Which database supports global distribution with multiple consistency models?” → Cosmos DB.
-
“Which consistency model guarantees order but not freshness?” → Consistent Prefix.
-
“Which partitioning key to use for IoT?” → DeviceID (high cardinality, even distribution).
-
“Company wants multi-model support (document + graph).” → Cosmos DB.
What to Expect in the Exam
-
Direct Q: “Which database allows global distribution with 99.999% SLA?” → Cosmos DB.
-
Scenario Q: “Company wants consistent session data across regions for e-commerce checkout.” → Session consistency.
-
Trick Q: “Cosmos DB has only one API.” → False (multi-model).