Intermediate LevelCloud Computing (AWS/GCP/Azure)
What is Azure Cosmos DB and how do its 5 well-defined consistency levels work?
❓ Interview Prompt: Explain Azure Cosmos DB multi-model NoSQL engine, Request Units (RUs), global distribution, and 5 consistency models.
Azure Cosmos DB is a globally distributed, multi-model NoSQL database service designed for single-digit millisecond response times.
The 5 Consistency Levels (CAP Theorem Spectrum):
Unlike databases offering only Strong vs Eventual consistency, Cosmos DB provides 5 precise choices:
1
Strong: Linearizable. Reads guaranteed to return most recent committed write. Highest latency.
2
Bounded Staleness: Reads lag behind writes by at most $K$ versions or $T$ time window.
3
Session (Default): Strong consistency within a single client session. Ideal for 90% of web apps!
4
Consistent Prefix: Guarantees reads never see out-of-order writes.
5
Eventual: Lowest latency and highest availability, but no ordering guarantees.
Code Implementation Example
typescript
import { CosmosClient } from '@azure/cosmos';
// Connecting to Azure Cosmos DB with Session consistency
const client = new CosmosClient({
endpoint: 'https://my-cosmos-db.documents.azure.com:443/',
key: process.env.COSMOS_KEY,
consistencyLevel: 'Session' // Session consistency
});💡Connecting to Azure Cosmos DB specifying Session consistency level.
🎯 Interview Key Takeaway
Azure Cosmos DB offers 5 well-defined consistency levels (Strong to Eventual), balancing latency against data freshness.
#Cosmos DB#Azure#NoSQL#Consistency Levels#Intermediate
Back to all Cloud Computing (AWS/GCP/Azure) Questions→