Why Cosmos DB?
Modern applications often need to serve global users with low latency while handling massive amounts of unstructured or semi-structured data. Traditional relational databases struggle with these demands. Cosmos DB is Azure’s fully managed, globally distributed, multi-model NoSQL database built for cloud-scale applications.
1. Cosmos DB Core Features
-
Global Distribution
-
Replicate data across multiple Azure regions.
-
Active-active (multi-master) writes supported.
-
Clients connect to the nearest region → low latency.
-
-
Multi-Model API Support
-
Core (SQL) API (document store, JSON).
-
Table API (key-value, like Azure Table Storage but advanced).
-
MongoDB API.
-
Cassandra API.
-
Gremlin API (graph database).
-
-
Tunable Consistency Levels (5 options):
-
Strong → strict consistency (like SQL).
-
Bounded Staleness → lag within N versions or time.
-
Session → per-session consistency (default, balances latency & correctness).
-
Consistent Prefix → reads in order, but may lag.
-
Eventual → fastest, no guarantees beyond eventual consistency.
-
-
Performance Scaling
-
Provisioned throughput (Request Units – RUs).
-
Autoscale mode (adjusts RU based on demand).
-
2. Cosmos DB Availability & Resiliency
-
Multi-region replication → 99.999% availability SLA (for reads).
-
Automatic failover or manual failover policies.
-
Write replication with conflict resolution policies.
3. Best Use Cases
-
Global e-commerce catalogs.
-
Gaming leaderboards and session data.
-
IoT telemetry ingestion.
-
Social media feeds.
-
Real-time personalization engines.
Example Enterprise Scenario
A social networking app requires:
-
Global read/write availability.
-
Fast response for users in US, EU, and Asia.
-
Ability to tolerate small staleness in data but not eventual consistency.
Correct design:
-
Use Cosmos DB SQL API with multi-master writes enabled.
-
Deploy across US, EU, Asia regions.
-
Set Session consistency (good balance between performance and correctness).
Confusion Buster
-
Cosmos DB vs Table Storage
-
Table Storage = simple, regional, cost-effective.
-
Cosmos DB = global, tunable consistency, multi-model.
-
-
Strong vs Session Consistency
-
Strong = strict correctness, higher latency.
-
Session = balance between performance + correctness (default).
-
-
Provisioned vs Autoscale Throughput
-
Provisioned = fixed RU allocation.
-
Autoscale = adjusts dynamically with workload.
-
Exam Tips
-
“Which Azure service provides multi-model, globally distributed NoSQL?” → Cosmos DB.
-
“Which Cosmos DB consistency level balances latency with correctness?” → Session.
-
“Which Cosmos DB API provides key-value store like Table Storage?” → Table API.
-
“Which Cosmos DB option supports global writes with conflict resolution?” → Multi-master.
What to Expect in the Exam
-
Direct Q: “Which database supports global distribution and tunable consistency?” → Cosmos DB.
-
Scenario Q: “Company needs 99.999% SLA for global database with low latency.” → Cosmos DB.
-
Scenario Q: “Retailer must deploy catalog DB with global writes and fast failover.” → Cosmos DB with multi-master.
-
Scenario Q: “App requires MongoDB API compatibility.” → Cosmos DB with MongoDB API.
-
Trick Q: “Azure Table Storage supports tunable consistency.” → False (only Cosmos DB does).